Advertisement
hadzhiyski

Untitled

Mar 14th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1.  public static class Constants
  2.     {
  3.         public static class Mail
  4.         {
  5.             public const string HOST = "zimbra.smartit.bg";
  6.             public const int PORT = 25;
  7.             public const bool USE_SSL = false;
  8.             public const string USERNAME = "";
  9.             public const string PASSWORD = "";
  10.             public const string FROM = "developers@easycredit.bg";
  11.         }
  12.     }
  13.  
  14. public static class Mail
  15. {
  16. public static void SendMail(string subject, string body, string mailTo)
  17.         {
  18.             SmtpClient smpt = new SmtpClient(Constants.Mail.HOST, Constants.Mail.PORT);
  19.             smpt.DeliveryMethod = SmtpDeliveryMethod.Network;
  20.  
  21.             if (!string.IsNullOrEmpty(Constants.Mail.USERNAME) && !string.IsNullOrEmpty(Constants.Mail.PASSWORD))
  22.             {
  23.                 smpt.UseDefaultCredentials = false;
  24.                 smpt.Credentials = new NetworkCredential(Constants.Mail.USERNAME, Constants.Mail.PASSWORD);
  25.             }
  26.  
  27.             smpt.EnableSsl = Constants.Mail.USE_SSL;
  28.  
  29.             MailMessage msg = new MailMessage(Constants.Mail.FROM, mailTo, subject, body);
  30.             msg.IsBodyHtml = true;
  31.  
  32.             using (smpt)
  33.             {
  34.                 smpt.Send(msg);
  35.             }
  36.         }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement