using System; using System.Collections.Generic; namespace ChadSoft { /// /// Encompasses everything you need to create and send email messages. /// public class EmailMessage { #region Private Variables private List _Recipients = new List(); private List _CC = new List(); private List _BCC = new List(); private List _Attachments = new List(); private string _Subject = String.Empty; private string _Body = String.Empty; private string _BodyHtml = String.Empty; private string _Sender = String.Empty; private bool _IsBodyHtml = false; #endregion Private Variables #region Constructors /// /// Initializes a new instance of the class. /// public EmailMessage() { } /// /// Initializes a new instance of the class. /// /// The sender's email address. /// The recipient's email address. /// The subject. /// The body. public EmailMessage(string senderEmail, string recipientEmail, string subject, string body) : this(senderEmail, recipientEmail, subject, body, true) { } /// /// Initializes a new /// /// The sender's email. /// The recipient's email. /// The subject. /// The body. /// If set to true [body is HTML]. public EmailMessage(string senderEmail, string recipientEmail, string subject, string body, bool bodyIsHtml) { Recipients.Add(recipientEmail); Sender = senderEmail; Subject = subject; Body = body; IsBodyHtml = bodyIsHtml; } #endregion Constructor #region Public Properties /// /// Gets or sets the list of recipients. /// /// the list of recipients. public List Recipients { get { return _Recipients; } set { _Recipients = value; } } /// /// Gets or sets the list of carbon-copied recipients. /// /// The list of carbon-copied recipients. public List CC { get { return _CC; } set { _CC = value; } } /// /// Gets or sets the list of blind carbon-copied recipients. /// /// The list of blind carbon-copied recipients. public List BCC { get { return _BCC; } set { _BCC = value; } } /// /// Gets or sets the attachments. /// /// The attachments. public List Attachments { get { return _Attachments; } set { _Attachments = value; } } /// /// Gets or sets the subject. /// /// The subject. public string Subject { get { return _Subject; } set { _Subject = value; } } /// /// Gets or sets the plain-text body. /// /// The plain-text body. public string Body { get { return _Body; } set { _Body = value; } } /// /// Gets or sets the body HTML. /// /// The body HTML. public string BodyHtml { get { return _BodyHtml; } set { _BodyHtml = value; } } /// /// Gets or sets the sender's name. /// /// The sender's name. public string Sender { get { return _Sender; } set { _Sender = value; } } /// /// Gets or sets a value indicating whether the body should be HTML. /// /// /// true if the body should be HTML; otherwise, the body will be sent as plain text. /// public bool IsBodyHtml { get { return _IsBodyHtml; } set { _IsBodyHtml = value; } } #endregion Public Properties #region Public Methods /// /// Sends this email message. /// public virtual bool Send() { return false; } #endregion Public Methods #region Public Static Methods /// /// Sends the specified sender email. /// /// The sender email. /// The recipient email. /// The subject. /// The body. /// Is message was successfully sent (not to be confused with successfully delivered!) public static bool Send(string senderEmail, string recipientEmail, string subject, string body) { return new EmailMessage(senderEmail, recipientEmail, subject, body, true).Send(); } #endregion Public Static Methods } }