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; } = new();
///
/// 抄送列表
///
public List CCList { get; } = new();
///
/// 密送列表
///
public List BCCList { get; } = new();
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)
{
this.Sender = Sender.SmtpClientInfo.SenderMailAddress;
this.SenderName = Sender.SmtpClientInfo.SenderName;
this.Subject = Subject;
this.Body = Body;
this.Priority = Priority;
this.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);
}
}
}