using System.Net.Mail; using Milimoe.FunGame.Core.Api.Transmittal; using Milimoe.FunGame.Core.Library.Constant; namespace Milimoe.FunGame.Core.Library.Common.Network { public class MailObject { /// /// 发件人邮箱 /// public string Sender { get; } = ""; /// /// 发件人名称 /// public string SenderName { get; } = ""; /// /// 邮件主题 /// public string Subject { get; } = ""; /// /// 邮件内容 /// public string Body { get; } = ""; /// /// 邮件优先级 /// public MailPriority Priority { get; } = MailPriority.Normal; /// /// 内容是否支持HTML /// public bool HTML { get; } = true; /// /// 收件人列表 /// public List ToList { get; } = []; /// /// 抄送列表 /// public List CCList { get; } = []; /// /// 密送列表 /// public List BCCList { get; } = []; public MailObject() { } /// /// 使用MailSender工具类创建邮件对象 /// /// public MailObject(MailSender sender) { this.Sender = sender.SmtpClientInfo.SenderMailAddress; this.SenderName = sender.SmtpClientInfo.SenderName; } /// /// 使用地址和名称创建邮件对象 /// /// /// public MailObject(string sender, string senderName) { this.Sender = sender; this.SenderName = senderName; } /// /// 使用地址和名称创建邮件对象,同时写主题、内容、单个收件人 /// /// /// /// /// public MailObject(MailSender sender, string subject, string body, string to) { this.Sender = sender.SmtpClientInfo.SenderMailAddress; this.SenderName = sender.SmtpClientInfo.SenderName; this.Subject = subject; this.Body = body; ToList.Add(to); } /// /// 使用地址和名称创建邮件对象,同时写主题、内容、单个收件人、单个抄送 /// /// /// /// /// /// public MailObject(MailSender sender, string subject, string body, string to, string cc) { this.Sender = sender.SmtpClientInfo.SenderMailAddress; this.SenderName = sender.SmtpClientInfo.SenderName; this.Subject = subject; this.Body = body; ToList.Add(to); CCList.Add(cc); } /// /// 完整的创建邮件对象 /// /// /// /// /// /// /// /// /// public MailObject(MailSender sender, string subject, string body, MailPriority priority, bool html, string[] toList, string[]? ccList = null, string[]? bccList = null) { Sender = sender.SmtpClientInfo.SenderMailAddress; SenderName = sender.SmtpClientInfo.SenderName; Subject = subject; Body = body; Priority = priority; HTML = html; AddTo(toList); if (ccList != null) AddCC(ccList); if (bccList != null) AddBCC(bccList); } /// /// 发送邮件 /// -- 适合创建一次性邮件并发送 -- /// /// /// public MailSendResult Send(MailSender sender) { return sender.Send(this); } /// /// 添加收件人 /// /// public void AddTo(string to) { if (!ToList.Contains(to)) ToList.Add(to); } /// /// 添加多个收件人 /// /// public void AddTo(params string[] to) { foreach (string t in to) AddTo(t); } /// /// 添加抄送 /// /// public void AddCC(string cc) { if (!CCList.Contains(cc)) CCList.Add(cc); } /// /// 添加多个抄送 /// /// public void AddCC(params string[] cc) { foreach (string c in cc) AddCC(c); } /// /// 添加密送 /// /// public void AddBCC(string bcc) { if (!BCCList.Contains(bcc)) BCCList.Add(bcc); } /// /// 添加多个密送 /// /// public void AddBCC(params string[] bcc) { foreach (string b in bcc) AddBCC(b); } } }