Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using SixtyThreeBits.ClassBase;
- using SixtyThreeBits.Libraries;
- using System.Net;
- using System.Net.Mail;
- namespace Core.Utilities
- {
- public class Mail : ObjectBase
- {
- #region Properties
- string Username;
- string Password;
- string SMTP;
- string From;
- int Port;
- #endregion Properties
- #region Constructors
- public Mail()
- {
- this.SMTP = AppSettings.SMTPAddress;
- this.Port = AppSettings.SMTPPort.ToInt().Value;
- this.Username = AppSettings.SMTPUsername;
- this.Password = AppSettings.SMTPPassword;
- this.From = AppSettings.SMTPFrom;
- }
- public Mail(string SMTP, int Port, string Username, string Password)
- {
- this.SMTP = SMTP;
- this.Port = Port;
- this.Username = Username;
- this.Password = Password;
- }
- #endregion Constructors
- #region Methods
- public bool Send(string To, string Subject, string Body, string ReplyTo = null)
- {
- return TryToReturn(string.Format("Send(To = {0}, Subject = {1}, Body = {2}, ReplyTo = {3})", To, Subject, Body, ReplyTo), () =>
- {
- var msg = new MailMessage(Username, To, Subject, Body);
- msg.From = new MailAddress(Username, From);
- msg.IsBodyHtml = true;
- using (var smtpClient = new SmtpClient(SMTP, Port))
- {
- smtpClient.Credentials = new NetworkCredential(Username, Password);
- smtpClient.EnableSsl = true;
- smtpClient.Send(msg);
- }
- return true;
- });
- }
- #endregion Methods
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement