/// <summary>Adds a recipient RFC 822 formatted email address to the MailMessage</summary> /// <param name="address">RFC 822 formatted email address that you want to add to the MailMessage</param> /// <param name="type">AddressType of the email address</param> /// <example> /// <code> /// MailMessage msg = new MailMessage("*****@*****.**", "*****@*****.**"); /// msg.AddRecipient("*****@*****.**", AddressType.Cc); /// </code> /// </example> public void AddRecipient(string address, AddressType type) { EmailAddress email = new EmailAddress(address); AddRecipient(email, type); }
/// <summary>Resets all of the MailMessage properties</summary> /// <example> /// <code> /// MailMessage msg = new MailMessage("*****@*****.**", "*****@*****.**"); /// msg.Reset(); /// </code> /// </example> public void Reset() { from = null; replyTo = null; recipientList.Clear(); ccList.Clear(); bccList.Clear(); customHeaders.Clear(); attachments.Clear(); subject = null; body = null; htmlBody = null; priority = null; mixedBoundary = null; altBoundary = null; charset = null; notification = false; }
/// <summary>Adds a recipient EmailAddress to the MailMessage</summary> /// <param name="address">EmailAddress that you want to add to the MailMessage</param> /// <param name="type">AddressType of the address</param> /// <example> /// <code> /// MailMessage msg = new MailMessage("*****@*****.**", "*****@*****.**"); /// EmailAddress cc = new EmailAddress("*****@*****.**"); /// msg.AddRecipient(cc, AddressType.Cc); /// </code> /// </example> public void AddRecipient(EmailAddress address, AddressType type) { try { switch(type) { case AddressType.To: recipientList.Add(address); break; case AddressType.Cc: ccList.Add(address); break; case AddressType.Bcc: bccList.Add(address); break; } } catch(Exception e) { throw new SmtpException("Exception in AddRecipient: " + e.ToString()); } }
/// <summary>Constructor using EmailAddress type</summary> /// <example> /// <code> /// EmailAddress from = new EmailAddress("*****@*****.**", "Support"); /// EmailAddress to = new EmailAddress("*****@*****.**", "Joe Smith"); /// MailMessage msg = new MailMessage(from, to); /// </code> /// </example> public MailMessage(EmailAddress sender, EmailAddress recipient) : this() { from = sender; recipientList.Add(recipient); }
static EmailAddress() { EmailAddress.InitializeRegex(); }