From a7fbd00530d8fbe11ff0c2f1f4e7662b8455aa67 Mon Sep 17 00:00:00 2001 From: he <109787524@qq.com> Date: Tue, 28 Oct 2025 11:40:45 +0800 Subject: [PATCH] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IRaCIS.Core.API/appsettings.Event_IRC.json | 1 + IRaCIS.Core.API/appsettings.Prod_IRC.json | 1 + IRaCIS.Core.API/appsettings.Test_IRC.json | 2 + .../appsettings.Test_IRC_PGSQL.json | 1 + IRaCIS.Core.API/appsettings.US_Prod_IRC.json | 1 + IRaCIS.Core.API/appsettings.US_Test_IRC.json | 1 + IRaCIS.Core.API/appsettings.US_Uat_IRC.json | 1 + IRaCIS.Core.API/appsettings.Uat_IRC.json | 1 + .../BusinessFilter/_Config/_AppSettings.cs | 2 + .../Common/EmailNoticeConfigService.cs | 68 ++++++++++++------- 10 files changed, 55 insertions(+), 24 deletions(-) diff --git a/IRaCIS.Core.API/appsettings.Event_IRC.json b/IRaCIS.Core.API/appsettings.Event_IRC.json index baae2fdc9..ce1553328 100644 --- a/IRaCIS.Core.API/appsettings.Event_IRC.json +++ b/IRaCIS.Core.API/appsettings.Event_IRC.json @@ -62,6 +62,7 @@ "SystemEmailSendConfig": { "Port": 465, "Host": "smtp.qiye.aliyun.com", + "Imap": "imap.qiye.aliyun.com", "FromEmail": "uat@extimaging.com", "FromName": "UAT_IRC", "AuthorizationCode": "SHzyyl2021", diff --git a/IRaCIS.Core.API/appsettings.Prod_IRC.json b/IRaCIS.Core.API/appsettings.Prod_IRC.json index 204935560..0a747f712 100644 --- a/IRaCIS.Core.API/appsettings.Prod_IRC.json +++ b/IRaCIS.Core.API/appsettings.Prod_IRC.json @@ -61,6 +61,7 @@ "SystemEmailSendConfig": { "Port": 465, "Host": "smtp.qiye.aliyun.com", + "Imap": "imap.qiye.aliyun.com", "FromEmail": "irc@extimaging.com", "FromName": "IRC Imaging System", "AuthorizationCode": "ExtImg@2022", diff --git a/IRaCIS.Core.API/appsettings.Test_IRC.json b/IRaCIS.Core.API/appsettings.Test_IRC.json index 005915204..fa496f94e 100644 --- a/IRaCIS.Core.API/appsettings.Test_IRC.json +++ b/IRaCIS.Core.API/appsettings.Test_IRC.json @@ -125,6 +125,8 @@ "Port": 465, // 企业邮箱SMTP服务器地址 "Host": "smtp.qiye.aliyun.com", + + "Imap": "imap.qiye.aliyun.com", // 发件人邮箱地址 "FromEmail": "test@extimaging.com", // 发件人显示名称 diff --git a/IRaCIS.Core.API/appsettings.Test_IRC_PGSQL.json b/IRaCIS.Core.API/appsettings.Test_IRC_PGSQL.json index cc576a790..d1a646f83 100644 --- a/IRaCIS.Core.API/appsettings.Test_IRC_PGSQL.json +++ b/IRaCIS.Core.API/appsettings.Test_IRC_PGSQL.json @@ -75,6 +75,7 @@ "SystemEmailSendConfig": { "Port": 465, "Host": "smtp.qiye.aliyun.com", + "Imap": "imap.qiye.aliyun.com", "FromEmail": "test@extimaging.com", "FromName": "Test_IRC", "AuthorizationCode": "SHzyyl2021", diff --git a/IRaCIS.Core.API/appsettings.US_Prod_IRC.json b/IRaCIS.Core.API/appsettings.US_Prod_IRC.json index b53efb63e..3740b6b9e 100644 --- a/IRaCIS.Core.API/appsettings.US_Prod_IRC.json +++ b/IRaCIS.Core.API/appsettings.US_Prod_IRC.json @@ -66,6 +66,7 @@ "SystemEmailSendConfig": { "Port": 587, "Host": "smtp-mail.outlook.com", + "Imap": "imap.qiye.aliyun.com", "FromEmail": "donotreply@elevateimaging.ai", "FromName": "LiLi System", "AuthorizationCode": "Q#669869497420ul", diff --git a/IRaCIS.Core.API/appsettings.US_Test_IRC.json b/IRaCIS.Core.API/appsettings.US_Test_IRC.json index c36487c73..e3c6cb14e 100644 --- a/IRaCIS.Core.API/appsettings.US_Test_IRC.json +++ b/IRaCIS.Core.API/appsettings.US_Test_IRC.json @@ -74,6 +74,7 @@ "SystemEmailSendConfig": { "Port": 587, "Host": "smtp-mail.outlook.com", + "Imap": "imap.qiye.aliyun.com", "FromEmail": "donotreply@elevateimaging.ai", "FromName": "LiLi System", "AuthorizationCode": "Q#669869497420ul", diff --git a/IRaCIS.Core.API/appsettings.US_Uat_IRC.json b/IRaCIS.Core.API/appsettings.US_Uat_IRC.json index a1b67ccee..9d777aa21 100644 --- a/IRaCIS.Core.API/appsettings.US_Uat_IRC.json +++ b/IRaCIS.Core.API/appsettings.US_Uat_IRC.json @@ -73,6 +73,7 @@ "SystemEmailSendConfig": { "Port": 587, "Host": "smtp-mail.outlook.com", + "Imap": "imap.qiye.aliyun.com", "FromEmail": "donotreply@elevateimaging.ai", "FromName": "LiLi System", "AuthorizationCode": "Q#669869497420ul", diff --git a/IRaCIS.Core.API/appsettings.Uat_IRC.json b/IRaCIS.Core.API/appsettings.Uat_IRC.json index 101bf028b..6f64d3f10 100644 --- a/IRaCIS.Core.API/appsettings.Uat_IRC.json +++ b/IRaCIS.Core.API/appsettings.Uat_IRC.json @@ -80,6 +80,7 @@ "SystemEmailSendConfig": { "Port": 465, "Host": "smtp.qiye.aliyun.com", + "Imap": "imap.qiye.aliyun.com", "FromEmail": "uat@extimaging.com", "FromName": "Uat IRC Imaging System", "AuthorizationCode": "SHzyyl2021", diff --git a/IRaCIS.Core.Application/BusinessFilter/_Config/_AppSettings.cs b/IRaCIS.Core.Application/BusinessFilter/_Config/_AppSettings.cs index 811ca1563..aa433b847 100644 --- a/IRaCIS.Core.Application/BusinessFilter/_Config/_AppSettings.cs +++ b/IRaCIS.Core.Application/BusinessFilter/_Config/_AppSettings.cs @@ -47,6 +47,8 @@ public class SystemEmailSendConfig public int Port { get; set; } public string Host { get; set; } = string.Empty; + + public string Imap { get; set; } = string.Empty; public string FromEmail { get; set; } = string.Empty; public string FromName { get; set; } = string.Empty; diff --git a/IRaCIS.Core.Application/Service/Common/EmailNoticeConfigService.cs b/IRaCIS.Core.Application/Service/Common/EmailNoticeConfigService.cs index cae69c208..b76bd597e 100644 --- a/IRaCIS.Core.Application/Service/Common/EmailNoticeConfigService.cs +++ b/IRaCIS.Core.Application/Service/Common/EmailNoticeConfigService.cs @@ -10,6 +10,7 @@ using IRaCIS.Core.Domain.Share; using MailKit; using MailKit.Net.Imap; using MailKit.Search; +using MailKit.Security; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using NPOI.SS.Formula.Functions; @@ -41,34 +42,53 @@ namespace IRaCIS.Core.Application.Contracts - - using var client = new ImapClient(); - await client.ConnectAsync(_systemEmailConfig.Host, 993, true); - await client.AuthenticateAsync(_systemEmailConfig.FromEmail, _systemEmailConfig.AuthorizationCode); - - var personal = client.GetFolder(client.PersonalNamespaces[0]); - var sent = personal.GetSubfolders() - .First(f => new[] { "已发送邮件", "Sent", "Sent Messages" } - .Contains(f.Name, StringComparer.OrdinalIgnoreCase)); - await sent.OpenAsync(FolderAccess.ReadOnly); - - List list= new List(); - for (int i = 0; i < sent.Count; i++) + using (var client = new ImapClient()) { - var msg = await sent.GetMessageAsync(i); - list.Add(new { - Subject= msg.Subject, - From= msg.From.ToString(), - To = msg.To.ToString(), - TextBody = msg.TextBody ?? "", - HtmlBody = msg.HtmlBody ?? "", - Date = msg.Date.UtcDateTime - }); + + + 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); + } } - await client.DisconnectAsync(true); - return list; + return true; }