邮件日志修改
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
06f10e38f5
commit
1427940224
|
|
@ -130,12 +130,27 @@ public class GetEmailInfoOutDto:EmailLogView
|
||||||
public class GetEmailInfoInDto
|
public class GetEmailInfoInDto
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
|
public Guid? TrialId { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class SynchronizationEmailInDto
|
||||||
|
{
|
||||||
|
public Guid? TrialId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public class ResendEmailInDto
|
public class ResendEmailInDto
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
|
public Guid? TrialId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class EmailAuthorization
|
||||||
|
{
|
||||||
|
public string FromEmail { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string AuthorizationCode { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EmailLogQuery:PageInput
|
public class EmailLogQuery:PageInput
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Mail;
|
using System.Net.Mail;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Panda.DynamicWebApi.Attributes;
|
||||||
namespace IRaCIS.Core.Application.Service;
|
namespace IRaCIS.Core.Application.Service;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -54,14 +55,14 @@ public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<PageOutput<EmailLogView>> GetEmailLogList(EmailLogQuery inDto)
|
public async Task<PageOutput<EmailLogView>> GetEmailLogList(EmailLogQuery inDto)
|
||||||
{
|
{
|
||||||
var emailFromName = await _trialRepository.Where(x=>x.Id==inDto.TrialId).Select(x=>x.EmailFromName).FirstOrDefaultAsync();
|
var emailFromEmail = await _trialRepository.Where(x=>x.Id==inDto.TrialId).Select(x=>x.EmailFromEmail).FirstOrDefaultAsync();
|
||||||
|
|
||||||
if (emailFromName.IsNullOrEmpty())
|
if (emailFromEmail.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
emailFromName = _systemEmailConfig.FromName;
|
emailFromEmail = _systemEmailConfig.FromEmail;
|
||||||
}
|
}
|
||||||
var emailLogQueryable = _emailLogRepository
|
var emailLogQueryable = _emailLogRepository
|
||||||
.Where(x=>x.SenderName== emailFromName)
|
.Where(x=>x.SenderAddress== emailFromEmail)
|
||||||
.WhereIf(inDto.EmailStartDate.HasValue, x => x.EmailDate >= inDto.EmailStartDate.Value)
|
.WhereIf(inDto.EmailStartDate.HasValue, x => x.EmailDate >= inDto.EmailStartDate.Value)
|
||||||
.WhereIf(inDto.EmailEndDate.HasValue, x => x.EmailDate <= inDto.EmailEndDate.Value)
|
.WhereIf(inDto.EmailEndDate.HasValue, x => x.EmailDate <= inDto.EmailEndDate.Value)
|
||||||
.WhereIf(inDto.EmailStateEnum.HasValue, x => x.EmailStateEnum == inDto.EmailStateEnum.Value)
|
.WhereIf(inDto.EmailStateEnum.HasValue, x => x.EmailStateEnum == inDto.EmailStateEnum.Value)
|
||||||
|
|
@ -119,8 +120,7 @@ public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
client.Connect(_systemEmailConfig.Imap, _systemEmailConfig.ImapPort, SecureSocketOptions.SslOnConnect);
|
await AuthenticateImap(client,inDto.TrialId);
|
||||||
AuthenticateImap(client);
|
|
||||||
var sentFolder = OpenSentFolder(client);
|
var sentFolder = OpenSentFolder(client);
|
||||||
var uid = new UniqueId(uint.Parse(emailInfo.UniqueId));
|
var uid = new UniqueId(uint.Parse(emailInfo.UniqueId));
|
||||||
var message = sentFolder.GetMessage(uid);
|
var message = sentFolder.GetMessage(uid);
|
||||||
|
|
@ -205,8 +205,7 @@ public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
client.Connect(_systemEmailConfig.Imap, _systemEmailConfig.ImapPort, SecureSocketOptions.SslOnConnect);
|
await AuthenticateImap(client,inDto.TrialId);
|
||||||
AuthenticateImap(client);
|
|
||||||
var sentFolder = OpenSentFolder(client);
|
var sentFolder = OpenSentFolder(client);
|
||||||
var uid = new UniqueId(uint.Parse(emailInfo.UniqueId));
|
var uid = new UniqueId(uint.Parse(emailInfo.UniqueId));
|
||||||
var message = sentFolder.GetMessage(uid);
|
var message = sentFolder.GetMessage(uid);
|
||||||
|
|
@ -267,7 +266,7 @@ public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IResponseOutput> SynchronizationEmail()
|
public async Task<IResponseOutput> SynchronizationEmail(SynchronizationEmailInDto inDto)
|
||||||
{
|
{
|
||||||
var maxTime = await _emailLogRepository.MaxAsync(t => t.EmailDate);
|
var maxTime = await _emailLogRepository.MaxAsync(t => t.EmailDate);
|
||||||
var startDate = maxTime ?? DateTime.MinValue;
|
var startDate = maxTime ?? DateTime.MinValue;
|
||||||
|
|
@ -279,8 +278,8 @@ public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
client.Connect(_systemEmailConfig.Imap, _systemEmailConfig.ImapPort, SecureSocketOptions.SslOnConnect);
|
|
||||||
AuthenticateImap(client);
|
await AuthenticateImap(client, inDto.TrialId);
|
||||||
var sentFolder = OpenSentFolder(client);
|
var sentFolder = OpenSentFolder(client);
|
||||||
|
|
||||||
var searchQuery = SearchQuery.All.And(SearchQuery.DeliveredAfter(startDate));
|
var searchQuery = SearchQuery.All.And(SearchQuery.DeliveredAfter(startDate));
|
||||||
|
|
@ -368,7 +367,7 @@ public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
|
||||||
// 第二步:处理收件箱中的邮件发送失败通知
|
// 第二步:处理收件箱中的邮件发送失败通知
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await ProcessInboxFailureNotifications(startDate);
|
await ProcessInboxFailureNotifications(startDate,inDto.TrialId);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -490,11 +489,27 @@ public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
|
||||||
return folder;
|
return folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AuthenticateImap(ImapClient client)
|
private async Task AuthenticateImap(ImapClient client, Guid? trialId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
client.Authenticate(_systemEmailConfig.FromEmail, _systemEmailConfig.AuthorizationCode);
|
EmailAuthorization authorization = new EmailAuthorization()
|
||||||
|
{
|
||||||
|
FromEmail = _systemEmailConfig.FromEmail,
|
||||||
|
AuthorizationCode = _systemEmailConfig.AuthorizationCode,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (trialId != null)
|
||||||
|
{
|
||||||
|
authorization = await _trialRepository.Where(x => x.Id == trialId.Value).Select(x => new EmailAuthorization()
|
||||||
|
{
|
||||||
|
AuthorizationCode = x.EmailAuthorizationCode,
|
||||||
|
FromEmail = x.EmailFromEmail
|
||||||
|
}).FirstNotNullAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
client.Connect(_systemEmailConfig.Imap, _systemEmailConfig.ImapPort, SecureSocketOptions.SslOnConnect);
|
||||||
|
client.Authenticate(authorization.FromEmail, authorization.AuthorizationCode);
|
||||||
}
|
}
|
||||||
catch (AuthenticationException)
|
catch (AuthenticationException)
|
||||||
{
|
{
|
||||||
|
|
@ -523,14 +538,14 @@ public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
|
||||||
/// 处理收件箱中的邮件发送失败通知
|
/// 处理收件箱中的邮件发送失败通知
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task ProcessInboxFailureNotifications(DateTime startTime)
|
public async Task ProcessInboxFailureNotifications(DateTime startTime, Guid? trialId)
|
||||||
{
|
{
|
||||||
using (var client = new ImapClient())
|
using (var client = new ImapClient())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
client.Connect(_systemEmailConfig.Imap, _systemEmailConfig.ImapPort, SecureSocketOptions.SslOnConnect);
|
|
||||||
AuthenticateImap(client);
|
await AuthenticateImap(client, trialId);
|
||||||
var inboxFolder = OpenInboxFolder(client);
|
var inboxFolder = OpenInboxFolder(client);
|
||||||
|
|
||||||
// 搜索可能包含失败通知的邮件
|
// 搜索可能包含失败通知的邮件
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue