/// <summary> /// 发送邮件(带附件) /// </summary> /// <param name="info">邮件信息</param> /// <param name="attachments">附件列表</param> public void Send(MailInfo info, params Attachment[] attachments) { var message = new MailMessage(); foreach (var item in attachments) { message.Attachments.Add(item); } Send(info, message); }
/// <summary> /// 内部发送邮件 /// </summary> /// <param name="info">邮件信息</param> /// <param name="message">邮件消息,默认为null</param> /// <param name="isSingleSend">是否群发单显,当邮件接收人为多个时,可选择该模式,即可对多个接收人分别发送,收件方不会知道这封邮件有多个收件人</param> protected void InternalSend(MailInfo info, MailMessage message = null, bool isSingleSend = false) { message = message ?? new MailMessage(); message.Subject = info.Subject; message.Body = info.Body; message.From = new MailAddress(Settings.From, Settings.DisplayName); if (!info.Replay.IsNullOrEmpty()) { message.ReplyToList.Add(new MailAddress(info.Replay)); } if (!info.CC.IsNullOrEmpty()) { message.CC.Add(info.CC); } if (isSingleSend && info.Receiver.Contains(",")) { foreach (var item in info.Receiver.Split(',')) { message.To.Clear(); message.To.Add(item); InternalSend(message, Settings.User, Settings.Password); } return; } if (!isSingleSend && info.Receiver.Contains(",")) { message.To.Add(info.Receiver); } else { message.To.Add(new MailAddress(info.Receiver, info.ReceiverName.IsNullOrEmpty() ? info.Receiver : info.ReceiverName)); } InternalSend(message, Settings.User, Settings.Password); }
/// <summary> /// 发送邮件 /// </summary> /// <param name="info">邮件信息</param> /// <param name="isSingleSend">是否群发单显,当邮件接收人为多个时,可选择该模式,即可对多个接收人分别发送,收件方不会知道这封邮件有多个收件人</param> /// <param name="message">邮件消息,默认为null</param> public void Send(MailInfo info, bool isSingleSend, MailMessage message = null) { InternalSend(info, message, isSingleSend); }
/// <summary> /// 发送邮件 /// </summary> /// <param name="info">邮件信息</param> /// <param name="message">邮件小,默认为null</param> public void Send(MailInfo info, MailMessage message = null) { InternalSend(info, message); }