// FIXME: should it throw a FormatException if the addresses are wrong? // (How is it possible to instantiate such a malformed MailAddress?) public MailMessage(MailAddress from, MailAddress to) : this() { if (from == null || to == null) throw new ArgumentNullException(); From = from; this.To.Add(to); }
internal Mail(MailAddress from, MailAddress[] to, MailAddress[] cc, MailAddress[] bcc, string subject, string html, string text, IHeader header = null ) : this(header) { From = from; To = to; Cc = cc; Bcc = bcc; _message.Subject = subject; Text = text; Html = html; TextTransferEncoding = TransferEncoding.SevenBit; HtmlTransferEncoding = TransferEncoding.SevenBit; }
/// <summary> /// Add to the 'To' address. /// </summary> /// <param name="address">single string eg. '*****@*****.**'</param> public void AddTo(string address) { var mailAddress = new MailAddress(address); _message.To.Add(mailAddress); }
/// <summary> /// Add to the 'CC' address. /// </summary> /// <param name="address">a single email address eg "*****@*****.**"</param> public void AddCc(string address) { var mailAddress = new MailAddress(address); _message.CC.Add(mailAddress); }
/// <summary> /// Add to the 'Bcc' address. /// </summary> /// <param name="addresssInfo">the dictionary keys are the email addresses, which points to a dictionary of /// key substitutionValues pairs mapping to other address codes, such as { [email protected] => { 'DisplayName' => 'Mr Foo' } }</param> public void AddBcc(IDictionary<string, IDictionary<string, string>> addresssInfo) { foreach (var address in addresssInfo.Keys) { var table = addresssInfo[address]; //DisplayName is the only option that this implementation of MailAddress implements. var mailAddress = new MailAddress(address, table.ContainsKey("DisplayName") ? table["DisplayName"] : null); _message.Bcc.Add(mailAddress); } }
/// <summary> /// Add to the 'Bcc' address. /// </summary> /// <param name="address">a single email as the input eg "*****@*****.**"</param> public void AddBcc(string address) { var mailAddress = new MailAddress(address); _message.Bcc.Add(mailAddress); }
/// <summary> /// Creates an instance of SendGrid's custom message object with mail parameters /// </summary> /// <param name="from">The email address of the sender</param> /// <param name="to">An array of the recipients</param> /// <param name="cc">Supported over SMTP, with future plans for support in the Web transport</param> /// <param name="bcc">Blind recipients</param> /// <param name="subject">The subject of the message</param> /// <param name="html">the html content for the message</param> /// <param name="text">the plain text part of the message</param> /// <param name="transport">Transport class to use for sending the message</param> /// <returns></returns> public static Mail GetInstance(MailAddress from, MailAddress[] to, MailAddress[] cc, MailAddress[] bcc, string subject, string html, string text) { var header = new Header(); return new Mail(from, to, cc, bcc, subject, html, text, header); }