diff --git a/IRaCIS.Core.Application/Service/Common/DTO/EmailLogViewModel.cs b/IRaCIS.Core.Application/Service/Common/DTO/EmailLogViewModel.cs index 3b2e63900..d05a5a8a9 100644 --- a/IRaCIS.Core.Application/Service/Common/DTO/EmailLogViewModel.cs +++ b/IRaCIS.Core.Application/Service/Common/DTO/EmailLogViewModel.cs @@ -23,9 +23,9 @@ public class EmailLogAddOrEdit { public Guid? Id { get; set; } - public List`1 Attachments { get; set; } + public string Attachments { get; set; } - public List`1 CcRecipients { get; set; } + public string CcRecipients { get; set; } public DateTime? EmailDate { get; set; } @@ -38,17 +38,17 @@ public class EmailLogAddOrEdit public string MessageId { get; set; } public string SenderAddress { get; set; } - - public List`1 ToRecipients { get; set; } + + public string ToRecipients { get; set; } public string UniqueId { get; set; } } public class EmailLogQuery:PageInput { - public List`1? Attachments { get; set; } - - public List`1? CcRecipients { get; set; } + public string Attachments { get; set; } + + public string CcRecipients { get; set; } public DateTime? EmailDate { get; set; } @@ -62,7 +62,7 @@ public class EmailLogQuery:PageInput public string? SenderAddress { get; set; } - public List`1? ToRecipients { get; set; } + public string ToRecipients { get; set; } public string? UniqueId { get; set; } } diff --git a/IRaCIS.Core.Application/Service/Common/EmailLogService.cs b/IRaCIS.Core.Application/Service/Common/EmailLogService.cs index f21753d42..ab31d96ca 100644 --- a/IRaCIS.Core.Application/Service/Common/EmailLogService.cs +++ b/IRaCIS.Core.Application/Service/Common/EmailLogService.cs @@ -4,26 +4,84 @@ // 生成时间 2025-10-28 06:22:42Z // 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。 //-------------------------------------------------------------------- -using IRaCIS.Core.Domain.Models; -using Microsoft.AspNetCore.Mvc; using IRaCIS.Core.Application.Interfaces; using IRaCIS.Core.Application.ViewModel; -using IRaCIS.Core.Infrastructure.Extention; -using System.Threading.Tasks; +using IRaCIS.Core.Domain.Models; using IRaCIS.Core.Infra.EFCore; +using IRaCIS.Core.Infrastructure.Extention; +using MailKit; +using MailKit.Net.Imap; +using MailKit.Search; +using MailKit.Security; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; +using System.Threading.Tasks; namespace IRaCIS.Core.Application.Service; [ ApiExplorerSettings(GroupName = "Test")] public class EmailLogService(IRepository _emailLogRepository, + IOptionsMonitor systemEmailConfig, IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer): BaseService, IEmailLogService { + private readonly SystemEmailSendConfig _systemEmailConfig = systemEmailConfig.CurrentValue; - - [HttpPost] + [HttpPost] public async Task> GetEmailLogList(EmailLogQuery inQuery) { - - var emailLogQueryable =_emailLogRepository + + List emailList = new List(); + + + + + + + using (var client = new ImapClient()) + { + + + try + { + // 连接阿里邮箱 IMAP 服务器(使用 SSL) + client.Connect(_systemEmailConfig.Imap, 993, SecureSocketOptions.SslOnConnect); + + // 登录 + client.Authenticate(_systemEmailConfig.FromEmail, _systemEmailConfig.AuthorizationCode); + + // 3. 获取发件箱文件夹 - 使用你找到的“已发送” + var sentFolder = client.GetFolder("已发送"); + sentFolder.Open(FolderAccess.ReadOnly); + + // 4. 搜索所有邮件(你可以在这里添加更精确的搜索条件) + var uids = sentFolder.Search(SearchQuery.All); + Console.WriteLine($"找到 {uids.Count} 封已发送邮件"); + + // 5. 遍历并处理邮件(示例中处理前10封) + foreach (var uid in uids.Take(10)) + { + var message = sentFolder.GetMessage(uid); + + // 输出邮件基本信息 + Console.WriteLine($"主题: {message.Subject}"); + Console.WriteLine($"收件人: {string.Join(", ", message.To.Mailboxes.Select(m => m.Address))}"); + Console.WriteLine($"日期: {message.Date.LocalDateTime:yyyy-MM-dd HH:mm:ss}"); + Console.WriteLine($"发件人: {message.From}"); + Console.WriteLine("----------------------------------"); + } + + sentFolder.Close(); + } + catch (Exception ex) + { + Console.WriteLine($"操作失败: {ex.Message}"); + } + finally + { + client.Disconnect(true); + } + } + + var emailLogQueryable =_emailLogRepository .ProjectTo(_mapper.ConfigurationProvider); var pageList= await emailLogQueryable.ToPagedListAsync(inQuery);