// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
using MailKit.Net.Smtp;
using MimeKit;
namespace Admin.NET.Core.Service;
///
/// 系统邮件发送服务
///
[ApiDescriptionSettings(Order = 370)]
public class SysEmailService : IDynamicApiController, ITransient
{
private readonly EmailOptions _emailOptions;
public SysEmailService(IOptions emailOptions)
{
_emailOptions = emailOptions.Value;
}
///
/// 发送邮件
///
///
///
///
[DisplayName("发送邮件")]
public async Task SendEmail([Required] string content, string title = "Admin.NET 系统邮件")
{
var message = new MimeMessage();
message.From.Add(new MailboxAddress(_emailOptions.DefaultFromEmail, _emailOptions.DefaultFromEmail));
message.To.Add(new MailboxAddress(_emailOptions.DefaultToEmail, _emailOptions.DefaultToEmail));
message.Subject = title;
message.Body = new TextPart("html")
{
Text = content
};
using var client = new SmtpClient();
client.Connect(_emailOptions.Host, _emailOptions.Port, _emailOptions.EnableSsl);
client.Authenticate(_emailOptions.UserName, _emailOptions.Password);
client.Send(message);
client.Disconnect(true);
await Task.CompletedTask;
}
}