邮件修改部署

Test.EIImageViewer
hang 2022-11-25 13:33:20 +08:00
parent 83909a58ed
commit 7284df03be
9 changed files with 130 additions and 47 deletions

View File

@ -22,6 +22,7 @@ using IRaCIS.Core.Application.MediatR.CommandAndQueries;
using IRaCIS.Core.Infra.EFCore.Common;
using Invio.Extensions.Authentication.JwtBearer;
using Microsoft.AspNetCore.SignalR;
using IRaCIS.Core.Domain.Share;
namespace IRaCIS.Core.API
{
@ -89,8 +90,10 @@ namespace IRaCIS.Core.API
.AddNewtonsoftJsonSetup(); // NewtonsoftJson 序列化 处理
services.AddOptions().Configure<SystemEmailSendConfig>( _configuration.GetSection("SystemEmailSendConfig"));
services.AddOptions().Configure<ServiceVerifyConfigOption>(_configuration.GetSection("BasicSystemConfig"));
//services.AddScoped<IAuditingData, AuditingData>();
//动态WebApi + UnifiedApiResultFilter 省掉控制器代码
services.AddDynamicWebApiSetup();

View File

@ -19,7 +19,14 @@
"OpenTrialRelationDelete": true,
"OpenLoginLimit": false
},
"SystemEmailSendConfig": {
"Port": 25,
"Host": "smtp.qiye.aliyun.com",
"FromEmail": "test@extimaging.com",
"FromName": "Test_IRC",
"AuthorizationCode": "SHzyyl2021"
}
}

View File

@ -8,7 +8,7 @@
},
//"RootUrl": "http://123.56.181.144:8060/",
"ConnectionStrings": {
"RemoteNew": "Server=123.56.94.154,1433\\MSSQLSERVER;Database=IRaCIS.Production;User ID=sa;Password=dev123456DEV;TrustServerCertificate=true"
"RemoteNew": "Server=101.132.193.237,1433;Database=IRaCIS.Production;User ID=sa;Password=zhanying2021;TrustServerCertificate=true"
},
"BasicSystemConfig": {
@ -17,6 +17,21 @@
"OpenSignDocumentBeforeWork": true,
"OpenLoginLimit": true
},
//"SystemEmailSendConfig": {
// "Port": 465,
// "Host": "smtp.163.com",
// "FromEmail": "zhou941003@qq.com",
// "FromName": "hangZhou",
// "AuthorizationCode": "sqfhlpfdvnexbcab"
//}
"SystemEmailSendConfig": {
"Port": 25,
"Host": "smtp.qiye.aliyun.com",
"FromEmail": "IRC@extimaging.com",
"FromName": "IRC",
"AuthorizationCode": "ExtImg@2022"
}

View File

@ -17,5 +17,16 @@
"OpenLoginLimit": true
},
"SystemEmailSendConfig": {
"Port": 25,
"Host": "smtp.qiye.aliyun.com",
"FromEmail": "uat@extimaging.com",
"FromName": "UAT_IRC",
"AuthorizationCode": "SHzyyl2021"
}
}

View File

@ -1,4 +1,5 @@
using MailKit;
using IRaCIS.Core.Domain.Share;
using MailKit;
using MailKit.Security;
using MimeKit;
@ -8,7 +9,7 @@ namespace IRaCIS.Core.Application.Helper;
public static class SendEmailHelper
{
public static async Task SendEmailAsync(MimeMessage messageToSend, EventHandler<MessageSentEventArgs>? messageSentSuccess = null)
public static async Task SendEmailAsync(MimeMessage messageToSend, SystemEmailSendConfig _systemEmailConfig, EventHandler<MessageSentEventArgs>? messageSentSuccess = null)
{
try
{
@ -22,9 +23,13 @@ public static class SendEmailHelper
smtp.ServerCertificateValidationCallback = (s, c, h, e) => true;
await smtp.ConnectAsync("smtp.qq.com", 465, SecureSocketOptions.SslOnConnect);
//await smtp.ConnectAsync("smtp.qq.com", 465, SecureSocketOptions.SslOnConnect);
await smtp.AuthenticateAsync("zhou941003@qq.com", "sqfhlpfdvnexbcab");
//await smtp.AuthenticateAsync("zhou941003@qq.com", "sqfhlpfdvnexbcab");
await smtp.ConnectAsync(_systemEmailConfig.Host, _systemEmailConfig.Port, SecureSocketOptions.Auto);
await smtp.AuthenticateAsync(_systemEmailConfig.FromEmail, _systemEmailConfig.AuthorizationCode);
await smtp.SendAsync(messageToSend);
@ -118,14 +123,14 @@ public static class SendEmailHelper
public class SMTPEmailConfig
{
public int Port { get; set; } = 465;
public int Port { get; set; }
public string Host { get; set; } = "smtp.163.com";
public string Host { get; set; }
public string UserName { get; set; } = "iracis_grr@163.com";
public string UserName { get; set; }
public string AuthorizationCode { get; set; } = "XLWVQKZAEKLDWOAH";
public string AuthorizationCode { get; set; }
//邮件HtmlBody
@ -134,7 +139,7 @@ public class SMTPEmailConfig
//发
public MailboxAddress FromEmailAddress { get; set; } = new MailboxAddress("GRR", "iracis_grr@163.com");
public MailboxAddress FromEmailAddress { get; set; }
//收
public List<MailboxAddress> ToMailAddressList { get; set; } = new List<MailboxAddress>();

View File

@ -7,6 +7,7 @@ using IRaCIS.Core.Application.Auth;
using AutoMapper;
using IRaCIS.Application.Contracts;
using Nito.AsyncEx;
using Microsoft.Extensions.Options;
namespace IRaCIS.Application.Services
{
@ -21,7 +22,7 @@ namespace IRaCIS.Application.Services
Task AddUserSendEmailAsync(Guid userId, string baseUrl, string routeUrl);
Task AdminResetPwdSendEmailAsync(Guid userId,string pwdNotMd5="123456");
Task AdminResetPwdSendEmailAsync(Guid userId, string pwdNotMd5 = "123456");
Task SiteSurveyUserJoinEmail(Guid trialId, Guid userId, string baseUrl, string rootUrl);
@ -52,6 +53,8 @@ namespace IRaCIS.Application.Services
private readonly AsyncLock _mutex = new AsyncLock();
private readonly SystemEmailSendConfig _systemEmailConfig;
public MailVerificationService(IRepository<VerificationCode> verificationCodeRepository,
@ -62,8 +65,9 @@ namespace IRaCIS.Application.Services
IRepository<Trial> trialRepository,
IRepository<UserType> userTypeRepository,
IRepository<Doctor> doctorTypeRepository,
IMapper mapper)
IMapper mapper, IOptionsMonitor<SystemEmailSendConfig> systemEmailConfig)
{
_systemEmailConfig = systemEmailConfig.CurrentValue;
_verificationCodeRepository = verificationCodeRepository;
_systemBasicDatarepository = systemBasicDatarepository;
@ -85,14 +89,15 @@ namespace IRaCIS.Application.Services
{
var messageToSend = new MimeMessage();
//发件地址
messageToSend.From.Add(new MailboxAddress("GRR", "zhou941003@qq.com"));
messageToSend.From.Add(new MailboxAddress(_systemEmailConfig.FromName, _systemEmailConfig.FromEmail));
//收件地址
messageToSend.To.Add(new MailboxAddress(userName, emailAddress));
//主题
messageToSend.Subject = "[来自展影IRC] 关于重置邮箱的提醒";
var builder = new BodyBuilder();
@ -136,7 +141,7 @@ namespace IRaCIS.Application.Services
};
await SendEmailHelper.SendEmailAsync(messageToSend, sucessHandle);
await SendEmailHelper.SendEmailAsync(messageToSend, _systemEmailConfig, sucessHandle);
}
@ -148,7 +153,7 @@ namespace IRaCIS.Application.Services
{
var messageToSend = new MimeMessage();
//发件地址
messageToSend.From.Add(new MailboxAddress("GRR", "zhou941003@qq.com"));
messageToSend.From.Add(new MailboxAddress(_systemEmailConfig.FromName, _systemEmailConfig.FromEmail));
//收件地址
messageToSend.To.Add(new MailboxAddress(String.Empty, emailAddress));
//主题
@ -198,7 +203,7 @@ namespace IRaCIS.Application.Services
await SendEmailHelper.SendEmailAsync(messageToSend, sucessHandle);
await SendEmailHelper.SendEmailAsync(messageToSend, _systemEmailConfig, sucessHandle);
}
//中心调研 登陆
@ -208,7 +213,7 @@ namespace IRaCIS.Application.Services
var messageToSend = new MimeMessage();
//发件地址
messageToSend.From.Add(new MailboxAddress("GRR", "zhou941003@qq.com"));
messageToSend.From.Add(new MailboxAddress(_systemEmailConfig.FromName, _systemEmailConfig.FromEmail));
//收件地址
messageToSend.To.Add(new MailboxAddress(String.Empty, emailAddress));
//主题
@ -259,7 +264,7 @@ namespace IRaCIS.Application.Services
await SendEmailHelper.SendEmailAsync(messageToSend, sucessHandle);
await SendEmailHelper.SendEmailAsync(messageToSend, _systemEmailConfig,sucessHandle);
}
@ -275,7 +280,7 @@ namespace IRaCIS.Application.Services
var messageToSend = new MimeMessage();
//发件地址
messageToSend.From.Add(new MailboxAddress("GRR", "zhou941003@qq.com"));
messageToSend.From.Add(new MailboxAddress(_systemEmailConfig.FromName, _systemEmailConfig.FromEmail));
//收件地址
messageToSend.To.Add(new MailboxAddress(sysUserInfo.FullName, sysUserInfo.EMail));
//主题
@ -299,7 +304,7 @@ namespace IRaCIS.Application.Services
var domain = baseUrl.Substring(0, baseUrl.IndexOf("/login"));
var redirectUrl = $"{domain}/api/User/UserRedirect?url={ System.Web.HttpUtility.UrlEncode(routeUrl) }";
var redirectUrl = $"{domain}/api/User/UserRedirect?url={System.Web.HttpUtility.UrlEncode(routeUrl)}";
using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile))
{
@ -319,17 +324,17 @@ namespace IRaCIS.Application.Services
messageToSend.Body = builder.ToMessageBody();
await SendEmailHelper.SendEmailAsync(messageToSend);
await SendEmailHelper.SendEmailAsync(messageToSend,_systemEmailConfig);
}
//管理员重置密码发送邮件
public async Task AdminResetPwdSendEmailAsync(Guid userId, string pwdNotMd5= "123456")
public async Task AdminResetPwdSendEmailAsync(Guid userId, string pwdNotMd5 = "123456")
{
var sysUserInfo = (await _userRepository.Where(t => t.Id == userId).Include(t => t.UserTypeRole).FirstOrDefaultAsync()).IfNullThrowException();
var messageToSend = new MimeMessage();
//发件地址
messageToSend.From.Add(new MailboxAddress("GRR", "zhou941003@qq.com"));
messageToSend.From.Add(new MailboxAddress(_systemEmailConfig.FromName, _systemEmailConfig.FromEmail));
//收件地址
messageToSend.To.Add(new MailboxAddress(sysUserInfo.FullName, sysUserInfo.EMail));
//主题
@ -364,7 +369,7 @@ namespace IRaCIS.Application.Services
messageToSend.Body = builder.ToMessageBody();
await SendEmailHelper.SendEmailAsync(messageToSend);
await SendEmailHelper.SendEmailAsync(messageToSend, _systemEmailConfig);
}
@ -377,11 +382,11 @@ namespace IRaCIS.Application.Services
var messageToSend = new MimeMessage();
//发件地址
messageToSend.From.Add(new MailboxAddress("GRR", "zhou941003@qq.com"));
messageToSend.From.Add(new MailboxAddress(_systemEmailConfig.FromName, _systemEmailConfig.FromEmail));
//收件地址
messageToSend.To.Add(new MailboxAddress(sysUserInfo.FullName, sysUserInfo.EMail));
//主题
messageToSend.Subject = $"[来自展影IRC] [{ trialInfo.ResearchProgramNo}]邀请信";
messageToSend.Subject = $"[来自展影IRC] [{trialInfo.ResearchProgramNo}]邀请信";
@ -410,7 +415,7 @@ namespace IRaCIS.Application.Services
var domain = baseUrl.Substring(0, baseUrl.IndexOf("/login"));
var redirectUrl = $"{domain}/api/User/UserRedirect?url={ System.Web.HttpUtility.UrlEncode(routeUrl) }";
var redirectUrl = $"{domain}/api/User/UserRedirect?url={System.Web.HttpUtility.UrlEncode(routeUrl)}";
builder.HtmlBody = string.Format(templateInfo,
sysUserInfo.FullName,
@ -425,7 +430,7 @@ namespace IRaCIS.Application.Services
messageToSend.Body = builder.ToMessageBody();
await SendEmailHelper.SendEmailAsync(messageToSend, null);
await SendEmailHelper.SendEmailAsync(messageToSend, _systemEmailConfig,null);
}
@ -440,11 +445,11 @@ namespace IRaCIS.Application.Services
var messageToSend = new MimeMessage();
//发件地址
messageToSend.From.Add(new MailboxAddress("GRR", "zhou941003@qq.com"));
messageToSend.From.Add(new MailboxAddress(_systemEmailConfig.FromName, _systemEmailConfig.FromEmail));
//收件地址
messageToSend.To.Add(new MailboxAddress(String.Empty, sysUserInfo.EMail));
//主题
messageToSend.Subject = $"[来自展影IRC] [{ trialInfo.ResearchProgramNo}]邀请信";
messageToSend.Subject = $"[来自展影IRC] [{trialInfo.ResearchProgramNo}]邀请信";
var builder = new BodyBuilder();
@ -471,7 +476,7 @@ namespace IRaCIS.Application.Services
var routeUrl = rootUrl + "?UserId=" + sysUserInfo.Id + "&Email=" + sysUserInfo.EMail + "&UserName=" + sysUserInfo.UserName + "&UserType=" + sysUserInfo.UserTypeRole.UserTypeShortName + "&access_token=" + token;
var redirectUrl = $"{domain}/api/User/UserRedirect?url={ System.Web.HttpUtility.UrlEncode(routeUrl) }";
var redirectUrl = $"{domain}/api/User/UserRedirect?url={System.Web.HttpUtility.UrlEncode(routeUrl)}";
builder.HtmlBody = string.Format(templateInfo,
sysUserInfo.FullName,
@ -489,7 +494,7 @@ namespace IRaCIS.Application.Services
messageToSend.Body = builder.ToMessageBody();
await SendEmailHelper.SendEmailAsync(messageToSend, null);
await SendEmailHelper.SendEmailAsync(messageToSend, _systemEmailConfig, null);
}
@ -526,7 +531,7 @@ namespace IRaCIS.Application.Services
var savedUser = await _userRepository.AddAsync(saveItem);
//下面获取Token 需要这部分信息
sysUserInfo =savedUser.Clone();
sysUserInfo = savedUser.Clone();
sysUserInfo.UserTypeRole = userType;
@ -544,11 +549,11 @@ namespace IRaCIS.Application.Services
var messageToSend = new MimeMessage();
//发件地址
messageToSend.From.Add(new MailboxAddress("GRR", "zhou941003@qq.com"));
messageToSend.From.Add(new MailboxAddress(_systemEmailConfig.FromName, _systemEmailConfig.FromEmail));
//收件地址
messageToSend.To.Add(new MailboxAddress(doctor.FullName, doctor.EMail));
//主题
messageToSend.Subject = $"[来自展影IRC] [{ trialInfo.ResearchProgramNo}]邀请信";
messageToSend.Subject = $"[来自展影IRC] [{trialInfo.ResearchProgramNo}]邀请信";
var builder = new BodyBuilder();
@ -582,7 +587,7 @@ namespace IRaCIS.Application.Services
var domain = baseUrl.Substring(0, baseUrl.IndexOf("/login"));
var redirectUrl = $"{domain}/api/User/UserRedirect?url={ System.Web.HttpUtility.UrlEncode(routeUrl) }";
var redirectUrl = $"{domain}/api/User/UserRedirect?url={System.Web.HttpUtility.UrlEncode(routeUrl)}";
builder.HtmlBody = string.Format(templateInfo,
sysUserInfo.FullName,
@ -597,7 +602,7 @@ namespace IRaCIS.Application.Services
messageToSend.Body = builder.ToMessageBody();
await SendEmailHelper.SendEmailAsync(messageToSend, null);
await SendEmailHelper.SendEmailAsync(messageToSend, _systemEmailConfig, null);
return sysUserInfo.Id;
}

View File

@ -1,9 +1,11 @@
using BeetleX.BNR;
using IRaCIS.Core.Application.Service;
using IRaCIS.Core.Domain.Share;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Options;
using System.Text.RegularExpressions;
@ -17,8 +19,21 @@ namespace IRaCIS.Application.Services
//private readonly IDistributedCache _cache;
public TestService(IRepository<Dictionary> dicRepository, IRepository<Trial> trialRepository/*, IDistributedCache cache*/)
private readonly IOptionsMonitor<SystemEmailSendConfig> _systemEmailConfig;
private readonly IOptionsMonitor<ServiceVerifyConfigOption> _basicConfig;
public TestService(IRepository<Dictionary> dicRepository, IRepository<Trial> trialRepository/*, IDistributedCache cache*/
, IOptionsMonitor<SystemEmailSendConfig> systemEmailConfig, IOptionsMonitor<ServiceVerifyConfigOption> basicConfig)
{
_systemEmailConfig = systemEmailConfig;
_basicConfig = basicConfig;
_dicRepository = dicRepository;
_trialRepository = trialRepository;
//_cache = cache;
@ -107,16 +122,20 @@ namespace IRaCIS.Application.Services
return findStr;
}
public string GetEnvironmentName( [FromServices] IWebHostEnvironment env)
[AllowAnonymous]
public async Task<object> GetEnvironmentName( [FromServices] IWebHostEnvironment env)
{
return env.EnvironmentName;
//update DicomInstance set Path = '/IRaCISData/TrialData/' + cast(DicomInstance.TrialId as varchar) + '/' + DicomInstance.SiteId + '/' + DicomInstance.SubjectId + '/' + DicomInstance.SubjectVisitId + '/Dicom/' + DicomInstance.StudyId + '/' + DicomInstance.Id + '.dcm'
//await _repository.BatchUpdateAsync<DicomInstance>(u=>u.Id!=Guid.Empty,t => new DicomInstance() { Path = $"/{StaticData.Folder.IRaCISDataFolder}/{StaticData.Folder.TrialDataFolder}/{t.TrialId}/{t.SiteId}/{t.SubjectId}/{t.SubjectVisitId}/{StaticData.Folder.DicomFolder}/{t.StudyId}/{t.Id}.dcm" });
//await _repository.BatchUpdateAsync<DicomInstance>(u => u.Path.Contains(".dcm"), t => new DicomInstance() { Path = $"/{StaticData.Folder.IRaCISDataFolder}/{StaticData.Folder.TrialDataFolder}/{t.TrialId}/{t.SiteId}/{t.SubjectId}/{t.SubjectVisitId}/{StaticData.Folder.DicomFolder}/{t.StudyId}/{t.Id}.dcm" });
//await _repository.BatchUpdateAsync<DicomInstance>(u => !u.Path.Contains(".dcm"), t => new DicomInstance() { Path = $"/{StaticData.Folder.IRaCISDataFolder}/{StaticData.Folder.TrialDataFolder}/{t.TrialId}/{t.SiteId}/{t.SubjectId}/{t.SubjectVisitId}/{StaticData.Folder.DicomFolder}/{t.StudyId}/{t.Id}" });
return new { env.EnvironmentName , EMailConfig= _systemEmailConfig.CurrentValue,BasicConfig= _basicConfig.CurrentValue} ;
// Load a document.
@ -195,9 +214,9 @@ namespace IRaCIS.Application.Services
public string PostData(List<TestModel> testModelList)
public string PostData(TestModel testModelList)
{
return string.Join(",", testModelList);
return String.Empty ;
}
}
@ -208,6 +227,8 @@ namespace IRaCIS.Application.Services
public string Id { get; set; }
public string Name { get; set; }
public DateTime? Time { get; set; }
}
}

View File

@ -29,6 +29,8 @@
SuperAdmin=8,
CRA=9,
SPM=10,

View File

@ -18,6 +18,20 @@ namespace IRaCIS.Core.Domain.Share
public bool OpenLoginLimit { get; set; }
}
public class SystemEmailSendConfig
{
public int Port { get; set; }
public string Host { get; set; }
public string FromEmail { get; set; }
public string FromName { get; set; }
public string AuthorizationCode { get; set; }
}
/// <summary>
/// 项目基础配置规则