修改邮件端口测试

This commit is contained in:
2022-05-18 16:48:24 +08:00
parent 341b176f41
commit e540c32bce
6 changed files with 118 additions and 145 deletions
@@ -1,59 +0,0 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using MiniExcelLibs;
namespace IRaCIS.Core.Application.Service;
public static class ExcelExportHelper
{
//MiniExcel_Export
public static async Task<IActionResult> DataExportAsync(string code, object data, string exportFileNamePrefix, IRepository<CommonDocument> _commonDocumentRepository, IWebHostEnvironment _hostEnvironment)
{
var doc = _commonDocumentRepository.AsQueryable(true).FirstOrDefault(t => t.Code == code);
if (doc == null)
{
throw new Exception("当前code 没找到对应的导出模板文件");
}
var rootPath = Directory.GetParent(_hostEnvironment.ContentRootPath.TrimEnd('\\'))?.FullName;
var filePath = Path.Combine(rootPath, doc.Path.Trim('/'));
if (!System.IO.File.Exists(filePath))
{
throw new Exception("服务器本地不存在该路径文件");
}
//模板路径
var tplPath = filePath;
#region MiniExcel
var memoryStream = new MemoryStream();
await MiniExcel.SaveAsByTemplateAsync(memoryStream, tplPath, data);
memoryStream.Seek(0, SeekOrigin.Begin);
return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
{
FileDownloadName = $"{exportFileNamePrefix}_{doc.Name.Substring(0,doc.Name.LastIndexOf('.'))}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx"
};
#endregion
#region Magicodes
////创建Excel导出对象
//IExportFileByTemplate exporter = new ExcelExporter();
////根据模板导出
//var result = await exporter.ExportBytesByTemplate(exportInfo, tplPath);
//return new XlsxFileResult(bytes: result, fileDownloadName: $"{doc.Name}_{DateTime.Now.ToString("yyyy-MM-dd:hh:mm:ss")}.xlsx");
#endregion
}
}
@@ -3,6 +3,8 @@ using IRaCIS.Core.Domain.Models;
using IRaCIS.Core.Domain.Share;
using MailKit.Security;
using MimeKit;
using IRaCIS.Core.Application.Helper;
using MailKit;
namespace IRaCIS.Application.Services
{
@@ -10,11 +12,11 @@ namespace IRaCIS.Application.Services
{
Task SendMail(Guid userId, string userName, string emailAddress, int verificationCode);
Task AnolymousSendEmail(string researchProgramNo ,string emailAddress, int verificationCode);
Task AnolymousSendEmail(string researchProgramNo, string emailAddress, int verificationCode);
Task SendMailEditEmail(Guid userId, string userName, string emailAddress, int verificationCode);
Task AnolymousSendEmailForResetAccount( string emailAddress, int verificationCode);
Task AnolymousSendEmailForResetAccount(string emailAddress, int verificationCode);
}
public class MailVerificationService : IMailVerificationService
@@ -52,42 +54,35 @@ namespace IRaCIS.Application.Services
此邮件属系统自动发出,无需回复。
祝您顺利!/Best Regards.
上海展影医疗科技有限公司"
上海展影医疗科技有限公司"
};
using (var smtp = new MailKit.Net.Smtp.SmtpClient())
{
smtp.MessageSent += (sender, args) =>
{
// args.Response
var code = verificationCode.ToString();
_ = _verificationCodeRepository.AddAsync(new VerificationCode()
{
CodeType = 0,
HasSend = true,
Code = code,
UserId = userId,
ExpirationTime = DateTime.Now.AddMinutes(3)
}).Result;
_ = _verificationCodeRepository.SaveChangesAsync().Result;
};
smtp.ServerCertificateValidationCallback = (s, c, h, e) => true;
EventHandler<MessageSentEventArgs> sucessHandle = (sender, args) =>
{
// args.Response
var code = verificationCode.ToString();
_ = _verificationCodeRepository.AddAsync(new VerificationCode()
{
CodeType = 0,
HasSend = true,
Code = code,
UserId = userId,
ExpirationTime = DateTime.Now.AddMinutes(3)
}).Result;
_ = _verificationCodeRepository.SaveChangesAsync().Result;
await smtp.ConnectAsync("smtp.163.com", 465, SecureSocketOptions.StartTls);
};
await smtp.AuthenticateAsync("iracis_grr@163.com", "XLWVQKZAEKLDWOAH");
await smtp.SendAsync(messageToSend);
await SendEmailHelper.SendEmailAsync(messageToSend, sucessHandle);
await smtp.DisconnectAsync(true);
}
}
//不登录 通过邮箱重置密码
public async Task AnolymousSendEmailForResetAccount( string emailAddress, int verificationCode)
public async Task AnolymousSendEmailForResetAccount(string emailAddress, int verificationCode)
{
var messageToSend = new MimeMessage();
//发件地址
@@ -107,40 +102,30 @@ namespace IRaCIS.Application.Services
祝您顺利!/Best Regards.
上海展影医疗科技有限公司"
};
using (var smtp = new MailKit.Net.Smtp.SmtpClient())
{
smtp.MessageSent += (sender, args) =>
{
// args.Response
var code = verificationCode.ToString();
_ = _verificationCodeRepository.AddAsync(new VerificationCode()
{
CodeType = Core.Domain.Share.VerifyType.Email,
HasSend = true,
Code = code,
UserId = Guid.Empty,//此时不知道用户
EmailOrPhone = emailAddress,
ExpirationTime = DateTime.Now.AddMinutes(3)
}).Result;
_ = _verificationCodeRepository.SaveChangesAsync().Result;
};
EventHandler<MessageSentEventArgs> sucessHandle = (sender, args) =>
{
var code = verificationCode.ToString();
_ = _verificationCodeRepository.AddAsync(new VerificationCode()
{
CodeType = Core.Domain.Share.VerifyType.Email,
HasSend = true,
Code = code,
UserId = Guid.Empty,//此时不知道用户
EmailOrPhone = emailAddress,
ExpirationTime = DateTime.Now.AddMinutes(3)
}).Result;
_ = _verificationCodeRepository.SaveChangesAsync().Result;
};
smtp.ServerCertificateValidationCallback = (s, c, h, e) => true;
await smtp.ConnectAsync("smtp.163.com", 465, SecureSocketOptions.StartTls);
await smtp.AuthenticateAsync("iracis_grr@163.com", "XLWVQKZAEKLDWOAH");
await smtp.SendAsync(messageToSend);
await smtp.DisconnectAsync(true);
}
await SendEmailHelper.SendEmailAsync(messageToSend, sucessHandle);
}
//中心调研 登陆
public async Task AnolymousSendEmail(string researchProgramNo,string emailAddress, int verificationCode)
{
public async Task AnolymousSendEmail(string researchProgramNo, string emailAddress, int verificationCode)
{
var messageToSend = new MimeMessage();
@@ -161,35 +146,29 @@ namespace IRaCIS.Application.Services
祝您顺利!/Best Regards.
上海展影医疗科技有限公司"
};
using (var smtp = new MailKit.Net.Smtp.SmtpClient())
EventHandler<MessageSentEventArgs> sucessHandle = (sender, args) =>
{
smtp.MessageSent += (sender, args) =>
{
// args.Response
var code = verificationCode.ToString();
_ = _verificationCodeRepository.AddAsync(new VerificationCode()
{
CodeType = VerifyType.Email,
HasSend = true,
Code = code,
UserId = Guid.Empty,//此时不知道用户
EmailOrPhone = emailAddress,
ExpirationTime = DateTime.Now.AddMinutes(3)
}).Result;
_ = _verificationCodeRepository.SaveChangesAsync().Result;
// args.Response
var code = verificationCode.ToString();
_ = _verificationCodeRepository.AddAsync(new VerificationCode()
{
CodeType = VerifyType.Email,
HasSend = true,
Code = code,
UserId = Guid.Empty,//此时不知道用户
EmailOrPhone = emailAddress,
ExpirationTime = DateTime.Now.AddMinutes(3)
}).Result;
_ = _verificationCodeRepository.SaveChangesAsync().Result;
};
};
smtp.ServerCertificateValidationCallback = (s, c, h, e) => true;
await smtp.ConnectAsync("smtp.163.com", 465, SecureSocketOptions.StartTls);
await SendEmailHelper.SendEmailAsync(messageToSend, sucessHandle);
await smtp.AuthenticateAsync("iracis_grr@163.com", "XLWVQKZAEKLDWOAH");
await smtp.SendAsync(messageToSend);
await smtp.DisconnectAsync(true);
}
}
@@ -218,35 +197,25 @@ namespace IRaCIS.Application.Services
祝您顺利!/Best Regards.
上海展影医疗科技有限公司"
};
using (var smtp = new MailKit.Net.Smtp.SmtpClient())
EventHandler<MessageSentEventArgs> sucessHandle = (sender, args) =>
{
smtp.MessageSent += (sender, args) =>
// args.Response
var code = verificationCode.ToString();
_ = _verificationCodeRepository.AddAsync(new VerificationCode()
{
// args.Response
var code = verificationCode.ToString();
_ = _verificationCodeRepository.AddAsync(new VerificationCode()
{
CodeType = 0,
HasSend = true,
Code = code,
UserId = userId,
ExpirationTime = DateTime.Now.AddMinutes(3)
}).Result;
_ = _verificationCodeRepository.SaveChangesAsync().Result;
CodeType = 0,
HasSend = true,
Code = code,
UserId = userId,
ExpirationTime = DateTime.Now.AddMinutes(3)
}).Result;
_ = _verificationCodeRepository.SaveChangesAsync().Result;
};
};
await SendEmailHelper.SendEmailAsync(messageToSend, sucessHandle);
smtp.ServerCertificateValidationCallback = (s, c, h, e) => true;
await smtp.ConnectAsync("smtp.163.com", 465, SecureSocketOptions.StartTls);
await smtp.AuthenticateAsync("iracis_grr@163.com", "XLWVQKZAEKLDWOAH");
await smtp.SendAsync(messageToSend);
await smtp.DisconnectAsync(true);
}
}