邮件发送模板

This commit is contained in:
2022-05-20 14:40:24 +08:00
parent 2fc4bbc5c1
commit c938a9c27e
3 changed files with 87 additions and 73 deletions
@@ -5,6 +5,7 @@ using MailKit.Security;
using MimeKit;
using IRaCIS.Core.Application.Helper;
using MailKit;
using Microsoft.AspNetCore.Hosting;
namespace IRaCIS.Application.Services
{
@@ -25,12 +26,16 @@ namespace IRaCIS.Application.Services
private readonly IRepository<SystemBasicData> _systemBasicDatarepository;
private readonly IWebHostEnvironment _hostEnvironment;
public MailVerificationService(IRepository<VerificationCode> verificationCodeRepository, IRepository<SystemBasicData> systemBasicDatarepository)
public MailVerificationService(IRepository<VerificationCode> verificationCodeRepository, IRepository<SystemBasicData> systemBasicDatarepository , IWebHostEnvironment hostEnvironment)
{
_verificationCodeRepository = verificationCodeRepository;
_systemBasicDatarepository = systemBasicDatarepository;
_hostEnvironment = hostEnvironment;
}
//重置邮箱
@@ -48,31 +53,24 @@ namespace IRaCIS.Application.Services
var builder = new BodyBuilder();
builder.HtmlBody = @$"<body style='font-family: 微软雅黑;padding: 0;margin: 0;'>
<div style='padding-left: 40px;background: #f6f6f6'>
<div style='padding-top: 20px;padding-bottom:40px'>
<div style='line-height: 40px;font-size: 18px'>
尊敬的{userName}, 您好:
</div>
<div style='line-height: 40px;padding-left: 40px;margin-bottom: 10px;'>
感谢您使用展影云平台。
</div>
<div>
您正在进行邮箱重置操作,验证码是: {verificationCode},请在3分钟内输入该验证码,进行后续操作。如非本人操作,请忽略该邮件。
</div>
<div>
此邮件属系统自动发出,无需回复。
</div>
<div>
祝您顺利!/Best Regards。
</div>
<div>
上海展影医疗科技有限公司
</div>
</div>
</div>
</body>";
var pathToFile = _hostEnvironment.WebRootPath
+ Path.DirectorySeparatorChar.ToString()
+ "EmailTemplate"
+ Path.DirectorySeparatorChar.ToString()
+ "UserOptCommon.html";
using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile))
{
var templateInfo = SourceReader.ReadToEnd();
builder.HtmlBody = string.Format(templateInfo,
$" 尊敬的 {userName} , ",
"您正在进行邮箱重置操作",
verificationCode
);
}
messageToSend.Body = builder.ToMessageBody();
@@ -115,30 +113,24 @@ namespace IRaCIS.Application.Services
var builder = new BodyBuilder();
builder.HtmlBody = @$"<body style='font-family: 微软雅黑;padding: 0;margin: 0;'>
<div style='padding-left: 40px;background: #f6f6f6'>
<div style='padding-top: 20px;padding-bottom:40px'>
<div style='line-height: 40px;font-size: 18px'>
您好:
</div>
<div style='line-height: 40px;padding-left: 40px;margin-bottom: 10px;'>
感谢您使用展影云平台。
</div>
<div>
您正在进行邮箱重置密码操作,验证码是: {verificationCode},请在3分钟内输入该验证码,进行后续操作。如非本人操作,请忽略该邮件。
</div>
<div>
此邮件属系统自动发出,无需回复。
</div>
<div>
祝您顺利!/Best Regards。
</div>
<div>
上海展影医疗科技有限公司
</div>
</div>
</div>
</body>";
var pathToFile = _hostEnvironment.WebRootPath
+ Path.DirectorySeparatorChar.ToString()
+ "EmailTemplate"
+ Path.DirectorySeparatorChar.ToString()
+ "UserOptCommon.html";
using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile))
{
var templateInfo = SourceReader.ReadToEnd();
builder.HtmlBody = string.Format(templateInfo,
"",
"您正在进行邮箱重置密码操作",
verificationCode
);
}
messageToSend.Body = builder.ToMessageBody();
@@ -182,31 +174,23 @@ namespace IRaCIS.Application.Services
var builder = new BodyBuilder();
builder.HtmlBody = @$"<body style='font-family: 微软雅黑;padding: 0;margin: 0;'>
<div style='padding-left: 40px;background: #f6f6f6'>
<div style='padding-top: 20px;padding-bottom:40px'>
<div style='line-height: 40px;font-size: 18px'>
您好:
</div>
<div style='line-height: 40px;padding-left: 40px;margin-bottom: 10px;'>
感谢您使用展影云平台。
</div>
<div>
您正在参与展影医疗IRC项目中心调研工作,验证码是: {verificationCode},请在3分钟内输入该验证码,进行后续操作。如非本人操作,请忽略该邮件。
</div>
<div>
此邮件属系统自动发出,无需回复。
</div>
<div>
祝您顺利!/Best Regards。
</div>
<div>
上海展影医疗科技有限公司
</div>
</div>
</div>
</body>";
var pathToFile = _hostEnvironment.WebRootPath
+ Path.DirectorySeparatorChar.ToString()
+ "EmailTemplate"
+ Path.DirectorySeparatorChar.ToString()
+ "UserOptCommon.html";
using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile))
{
var templateInfo = SourceReader.ReadToEnd();
builder.HtmlBody = string.Format(templateInfo,
"",
"您正在参与展影医疗IRC项目中心调研工作",
verificationCode
);
}
messageToSend.Body = builder.ToMessageBody();