/// <summary> /// 设置邮件发信人信息 /// </summary> /// <param name="from">发信人地址</param> /// <param name="displayName">发信人显示名</param> public void SetFrom(string from, string displayName = null) { if (!MailAudit.ValidateRecipients(from)) { throw new ArgumentException("The mail's from is invalid."); } this.mailMessage.From = new MailAddress(from, displayName); }
/// <summary> /// 添加收件人。 /// 若收件人不符合 mail 格式,将会被移除 /// </summary> /// <param name="to">要添加的收件人</param> public void AddTo(string to) { if (!MailAudit.ValidateRecipients(to)) { return; } this.mailMessage.To.Add(new MailAddress(to)); }
/// <summary> /// 添加密送人。 /// 若密送不符合 mail 格式,将会被移除 /// </summary> /// <param name="bcc">要添加的密送人</param> public void AddBcc(string bcc) { if (!MailAudit.ValidateRecipients(bcc)) { return; } this.mailMessage.Bcc.Add(new MailAddress(bcc)); }
/// <summary> /// 添加抄送人。 /// 若抄送人不符合 mail 格式,将会被移除 /// </summary> /// <param name="cc">要添加的抄送人</param> public void AddCc(string cc) { if (!MailAudit.ValidateRecipients(cc)) { return; } this.mailMessage.CC.Add(new MailAddress(cc)); }