mirror of
https://github.com/project-redbud/FunGame-Core.git
synced 2025-04-22 03:59:35 +08:00

* 添加了 SQLHelperFactory;完善了物品的描述信息;一些代码风格修改 * 构造的物品默认 1 级;为服务器插件添加控制器;添加邮件发送器的工厂;在物品中添加魔法技能组
109 lines
3.4 KiB
C#
109 lines
3.4 KiB
C#
using System.Net.Mail;
|
|
using Milimoe.FunGame.Core.Library.Common.Network;
|
|
using Milimoe.FunGame.Core.Library.Constant;
|
|
using Milimoe.FunGame.Core.Model;
|
|
using Milimoe.FunGame.Core.Service;
|
|
|
|
namespace Milimoe.FunGame.Core.Api.Transmittal
|
|
{
|
|
public class MailSender : IDisposable
|
|
{
|
|
/// <summary>
|
|
/// 邮件服务内部ID
|
|
/// </summary>
|
|
public Guid MailSenderID { get; }
|
|
|
|
/// <summary>
|
|
/// Smtp客户端信息
|
|
/// </summary>
|
|
public SmtpClientInfo SmtpClientInfo => _SmtpClientInfo;
|
|
|
|
/// <summary>
|
|
/// 上一个邮件发送的结果
|
|
/// </summary>
|
|
public MailSendResult LastestResult => _LastestResult;
|
|
|
|
/// <summary>
|
|
/// 上一个邮件的发送错误信息(如果发送失败)
|
|
/// </summary>
|
|
public string ErrorMsg => _ErrorMsg;
|
|
|
|
/**
|
|
* 内部变量
|
|
*/
|
|
private readonly SmtpClientInfo _SmtpClientInfo;
|
|
private MailSendResult _LastestResult = MailSendResult.NotSend;
|
|
private string _ErrorMsg = "";
|
|
|
|
/// <summary>
|
|
/// 创建邮件服务
|
|
/// </summary>
|
|
/// <param name="senderMailAddress"></param>
|
|
/// <param name="senderName"></param>
|
|
/// <param name="senderPassword"></param>
|
|
/// <param name="host"></param>
|
|
/// <param name="port"></param>
|
|
/// <param name="ssl"></param>
|
|
public MailSender(string senderMailAddress, string senderName, string senderPassword, string host, int port, bool ssl)
|
|
{
|
|
MailSenderID = Guid.NewGuid();
|
|
_SmtpClientInfo = new SmtpClientInfo(senderMailAddress, senderName, senderPassword, host, port, ssl);
|
|
if (!MailManager.MailSenders.ContainsKey(MailSenderID)) MailManager.MailSenders.Add(MailSenderID, this);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建完整邮件对象
|
|
/// </summary>
|
|
/// <param name="subject"></param>
|
|
/// <param name="body"></param>
|
|
/// <param name="priority"></param>
|
|
/// <param name="html"></param>
|
|
/// <param name="toList"></param>
|
|
/// <param name="ccList"></param>
|
|
/// <param name="bccList"></param>
|
|
/// <returns></returns>
|
|
public MailObject CreateMail(string subject, string body, MailPriority priority, bool html, string[] toList, string[]? ccList = null, string[]? bccList = null)
|
|
{
|
|
return new MailObject(this, subject, body, priority, html, toList, ccList, bccList);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发送邮件
|
|
/// </summary>
|
|
/// <param name="mail"></param>
|
|
/// <returns></returns>
|
|
public MailSendResult Send(MailObject mail)
|
|
{
|
|
_LastestResult = MailManager.Send(this, mail, out _ErrorMsg);
|
|
return _LastestResult;
|
|
}
|
|
|
|
private bool _isDisposed = false;
|
|
|
|
/// <summary>
|
|
/// 关闭邮件服务
|
|
/// </summary>
|
|
public void Dispose()
|
|
{
|
|
Dispose(true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关闭邮件服务
|
|
/// </summary>
|
|
/// <param name="disposing"></param>
|
|
protected void Dispose(bool disposing)
|
|
{
|
|
if (!_isDisposed)
|
|
{
|
|
if (disposing)
|
|
{
|
|
MailManager.Dispose(this);
|
|
}
|
|
}
|
|
_isDisposed = true;
|
|
}
|
|
}
|
|
}
|