Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //***************************************************************************
- // Author Iliya Popov 20.02.2021 //
- //***************************************************************************
- using System;
- using System.Net;
- using System.Net.Mail;
- namespace EmailClient
- {
- class EmailClient
- {
- private const string emServer = "mail.server";
- private const byte emPort = "server port";// default 25
- private const string passEmailAccount = "your password";
- static void Main(string[] args)
- {
- string toEml, subject, contentTxt;
- do
- {
- Console.Write("Send email to: ");
- toEml = Console.ReadLine();
- Console.Write("Subject: ");
- subject = Console.ReadLine();
- Console.WriteLine("Text: ");
- contentTxt = Console.ReadLine();
- }while (sendEmail(toEml, subject, contentTxt));
- Console.ReadKey();
- }
- private static Boolean sendEmail(string toTxt, string subjectTxt, string bodyTxt)
- {
- SmtpClient smClient = new SmtpClient(emServer, emPort);
- smClient.Credentials = new NetworkCredential(fromEmail, passEmailAccount);
- MailMessage msg = new MailMessage();
- msg.From = new MailAddress(fromEmail);
- msg.To.Add(new MailAddress(toTxt));
- msg.Subject = subjectTxt;
- msg.Body = bodyTxt;
- try
- {
- smClient.Send(msg);
- Console.WriteLine("message sent successfully!");
- return false;
- }
- catch (SmtpException ex)
- {
- Console.WriteLine("Error send msg, {0}", ex);
- return true;
- }
- finally
- {
- smClient.Dispose();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment