优化邮件服务
This commit is contained in:
parent
da14901f3e
commit
cf27c7115c
@ -74,7 +74,8 @@ namespace ZR.Admin.WebApi.Controllers
|
|||||||
{
|
{
|
||||||
return ToResponse(ApiResult.Error($"请配置邮箱信息"));
|
return ToResponse(ApiResult.Error($"请配置邮箱信息"));
|
||||||
}
|
}
|
||||||
MailHelper mailHelper = new(OptionsSetting.MailOptions.From, OptionsSetting.MailOptions.Smtp, OptionsSetting.MailOptions.Port, OptionsSetting.MailOptions.Password);
|
|
||||||
|
MailHelper mailHelper = new();
|
||||||
|
|
||||||
string[] toUsers = sendEmailVo.ToUser.Split(",", StringSplitOptions.RemoveEmptyEntries);
|
string[] toUsers = sendEmailVo.ToUser.Split(",", StringSplitOptions.RemoveEmptyEntries);
|
||||||
if (sendEmailVo.SendMe)
|
if (sendEmailVo.SendMe)
|
||||||
|
|||||||
@ -143,7 +143,7 @@ namespace ZR.Admin.WebApi
|
|||||||
//×¢²áREDIS ·şÎñ
|
//×¢²áREDIS ·şÎñ
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
RedisServer.Initalize();
|
//RedisServer.Initalize();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,13 +47,14 @@
|
|||||||
//邮箱配置信息
|
//邮箱配置信息
|
||||||
"MailOptions": {
|
"MailOptions": {
|
||||||
//发送人邮箱
|
//发送人邮箱
|
||||||
"From": "xxxx@qq.com",
|
"From": "", //eg:xxxx@qq.com
|
||||||
//发送人邮箱密码
|
//发送人邮箱密码
|
||||||
"Password": "123456",
|
"Password": "123456",
|
||||||
//协议
|
//协议
|
||||||
"Smtp": "smtp.qq.com",
|
"Smtp": "smtp.qq.com",
|
||||||
"Port": 587
|
"Port": 587
|
||||||
},
|
},
|
||||||
|
//redis服务配置
|
||||||
"RedisServer": {
|
"RedisServer": {
|
||||||
"Cache": "127.0.0.1:6379,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=cache:",
|
"Cache": "127.0.0.1:6379,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=cache:",
|
||||||
"Session": "127.0.0.1:6379,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=session:"
|
"Session": "127.0.0.1:6379,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=session:"
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using MailKit.Net.Smtp;
|
using Infrastructure;
|
||||||
|
using MailKit.Net.Smtp;
|
||||||
using MimeKit;
|
using MimeKit;
|
||||||
using MimeKit.Text;
|
using MimeKit.Text;
|
||||||
using System;
|
using System;
|
||||||
@ -30,7 +31,16 @@ namespace ZR.Common
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool UseSsl { get; set; } = false;
|
public bool UseSsl { get; set; } = false;
|
||||||
public string mailSign = @"";
|
public string mailSign = @"";
|
||||||
|
private readonly MailOptions mailOptions = new();
|
||||||
|
|
||||||
|
public MailHelper()
|
||||||
|
{
|
||||||
|
ConfigUtils.Instance.Bind("MailOptions", mailOptions);
|
||||||
|
FromEmail = mailOptions.From;
|
||||||
|
Smtp = mailOptions.Smtp;
|
||||||
|
FromPwd = mailOptions.Password;
|
||||||
|
Port = mailOptions.Port;
|
||||||
|
}
|
||||||
public MailHelper(string fromEmail, string smtp, int port, string fromPwd)
|
public MailHelper(string fromEmail, string smtp, int port, string fromPwd)
|
||||||
{
|
{
|
||||||
FromEmail = fromEmail;
|
FromEmail = fromEmail;
|
||||||
@ -82,7 +92,6 @@ namespace ZR.Common
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 发送邮件
|
/// 发送邮件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="toName"></param>
|
|
||||||
/// <param name="toAddress"></param>
|
/// <param name="toAddress"></param>
|
||||||
/// <param name="subject"></param>
|
/// <param name="subject"></param>
|
||||||
/// <param name="text"></param>
|
/// <param name="text"></param>
|
||||||
@ -141,7 +150,7 @@ namespace ZR.Common
|
|||||||
using (var client = new SmtpClient())
|
using (var client = new SmtpClient())
|
||||||
{
|
{
|
||||||
client.ServerCertificateValidationCallback = (s, c, h, e) => true;
|
client.ServerCertificateValidationCallback = (s, c, h, e) => true;
|
||||||
|
|
||||||
//Smtp服务器
|
//Smtp服务器
|
||||||
//client.Connect("smtp.qq.com", 587, false);
|
//client.Connect("smtp.qq.com", 587, false);
|
||||||
client.Connect(Smtp, Port, true);
|
client.Connect(Smtp, Port, true);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user