Advertisement
Guest User

Untitled

a guest
Mar 17th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 KB | None | 0 0
  1. using SixtyThreeBits.ClassBase;
  2. using SixtyThreeBits.Libraries;
  3. using System.Net;
  4. using System.Net.Mail;
  5.  
  6.  
  7. namespace Core.Utilities
  8. {
  9.     public class Mail : ObjectBase
  10.     {
  11.         #region Properties
  12.         string Username;
  13.         string Password;
  14.         string SMTP;
  15.         string From;
  16.         int Port;
  17.         #endregion Properties
  18.  
  19.         #region Constructors
  20.         public Mail()
  21.         {
  22.             this.SMTP = AppSettings.SMTPAddress;
  23.             this.Port = AppSettings.SMTPPort.ToInt().Value;
  24.             this.Username = AppSettings.SMTPUsername;
  25.             this.Password = AppSettings.SMTPPassword;
  26.             this.From = AppSettings.SMTPFrom;
  27.         }
  28.  
  29.         public Mail(string SMTP, int Port, string Username, string Password)
  30.         {
  31.             this.SMTP = SMTP;
  32.             this.Port = Port;
  33.             this.Username = Username;
  34.             this.Password = Password;
  35.         }
  36.         #endregion Constructors
  37.  
  38.         #region Methods
  39.         public bool Send(string To, string Subject, string Body, string ReplyTo = null)
  40.         {
  41.             return TryToReturn(string.Format("Send(To = {0}, Subject = {1}, Body = {2}, ReplyTo = {3})", To, Subject, Body, ReplyTo), () =>
  42.             {
  43.  
  44.  
  45.                 var msg = new MailMessage(Username, To, Subject, Body);
  46.                 msg.From = new MailAddress(Username, From);
  47.                 msg.IsBodyHtml = true;
  48.                 using (var smtpClient = new SmtpClient(SMTP, Port))
  49.                 {
  50.                     smtpClient.Credentials = new NetworkCredential(Username, Password);
  51.                     smtpClient.EnableSsl = true;
  52.                     smtpClient.Send(msg);
  53.                 }
  54.  
  55.                 return true;
  56.             });
  57.         }
  58.         #endregion Methods
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement