邮件日志
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
785d5ec869
commit
a7fbd00530
|
|
@ -62,6 +62,7 @@
|
||||||
"SystemEmailSendConfig": {
|
"SystemEmailSendConfig": {
|
||||||
"Port": 465,
|
"Port": 465,
|
||||||
"Host": "smtp.qiye.aliyun.com",
|
"Host": "smtp.qiye.aliyun.com",
|
||||||
|
"Imap": "imap.qiye.aliyun.com",
|
||||||
"FromEmail": "uat@extimaging.com",
|
"FromEmail": "uat@extimaging.com",
|
||||||
"FromName": "UAT_IRC",
|
"FromName": "UAT_IRC",
|
||||||
"AuthorizationCode": "SHzyyl2021",
|
"AuthorizationCode": "SHzyyl2021",
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@
|
||||||
"SystemEmailSendConfig": {
|
"SystemEmailSendConfig": {
|
||||||
"Port": 465,
|
"Port": 465,
|
||||||
"Host": "smtp.qiye.aliyun.com",
|
"Host": "smtp.qiye.aliyun.com",
|
||||||
|
"Imap": "imap.qiye.aliyun.com",
|
||||||
"FromEmail": "irc@extimaging.com",
|
"FromEmail": "irc@extimaging.com",
|
||||||
"FromName": "IRC Imaging System",
|
"FromName": "IRC Imaging System",
|
||||||
"AuthorizationCode": "ExtImg@2022",
|
"AuthorizationCode": "ExtImg@2022",
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,8 @@
|
||||||
"Port": 465,
|
"Port": 465,
|
||||||
// 企业邮箱SMTP服务器地址
|
// 企业邮箱SMTP服务器地址
|
||||||
"Host": "smtp.qiye.aliyun.com",
|
"Host": "smtp.qiye.aliyun.com",
|
||||||
|
|
||||||
|
"Imap": "imap.qiye.aliyun.com",
|
||||||
// 发件人邮箱地址
|
// 发件人邮箱地址
|
||||||
"FromEmail": "test@extimaging.com",
|
"FromEmail": "test@extimaging.com",
|
||||||
// 发件人显示名称
|
// 发件人显示名称
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,7 @@
|
||||||
"SystemEmailSendConfig": {
|
"SystemEmailSendConfig": {
|
||||||
"Port": 465,
|
"Port": 465,
|
||||||
"Host": "smtp.qiye.aliyun.com",
|
"Host": "smtp.qiye.aliyun.com",
|
||||||
|
"Imap": "imap.qiye.aliyun.com",
|
||||||
"FromEmail": "test@extimaging.com",
|
"FromEmail": "test@extimaging.com",
|
||||||
"FromName": "Test_IRC",
|
"FromName": "Test_IRC",
|
||||||
"AuthorizationCode": "SHzyyl2021",
|
"AuthorizationCode": "SHzyyl2021",
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@
|
||||||
"SystemEmailSendConfig": {
|
"SystemEmailSendConfig": {
|
||||||
"Port": 587,
|
"Port": 587,
|
||||||
"Host": "smtp-mail.outlook.com",
|
"Host": "smtp-mail.outlook.com",
|
||||||
|
"Imap": "imap.qiye.aliyun.com",
|
||||||
"FromEmail": "donotreply@elevateimaging.ai",
|
"FromEmail": "donotreply@elevateimaging.ai",
|
||||||
"FromName": "LiLi System",
|
"FromName": "LiLi System",
|
||||||
"AuthorizationCode": "Q#669869497420ul",
|
"AuthorizationCode": "Q#669869497420ul",
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,7 @@
|
||||||
"SystemEmailSendConfig": {
|
"SystemEmailSendConfig": {
|
||||||
"Port": 587,
|
"Port": 587,
|
||||||
"Host": "smtp-mail.outlook.com",
|
"Host": "smtp-mail.outlook.com",
|
||||||
|
"Imap": "imap.qiye.aliyun.com",
|
||||||
"FromEmail": "donotreply@elevateimaging.ai",
|
"FromEmail": "donotreply@elevateimaging.ai",
|
||||||
"FromName": "LiLi System",
|
"FromName": "LiLi System",
|
||||||
"AuthorizationCode": "Q#669869497420ul",
|
"AuthorizationCode": "Q#669869497420ul",
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,7 @@
|
||||||
"SystemEmailSendConfig": {
|
"SystemEmailSendConfig": {
|
||||||
"Port": 587,
|
"Port": 587,
|
||||||
"Host": "smtp-mail.outlook.com",
|
"Host": "smtp-mail.outlook.com",
|
||||||
|
"Imap": "imap.qiye.aliyun.com",
|
||||||
"FromEmail": "donotreply@elevateimaging.ai",
|
"FromEmail": "donotreply@elevateimaging.ai",
|
||||||
"FromName": "LiLi System",
|
"FromName": "LiLi System",
|
||||||
"AuthorizationCode": "Q#669869497420ul",
|
"AuthorizationCode": "Q#669869497420ul",
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,7 @@
|
||||||
"SystemEmailSendConfig": {
|
"SystemEmailSendConfig": {
|
||||||
"Port": 465,
|
"Port": 465,
|
||||||
"Host": "smtp.qiye.aliyun.com",
|
"Host": "smtp.qiye.aliyun.com",
|
||||||
|
"Imap": "imap.qiye.aliyun.com",
|
||||||
"FromEmail": "uat@extimaging.com",
|
"FromEmail": "uat@extimaging.com",
|
||||||
"FromName": "Uat IRC Imaging System",
|
"FromName": "Uat IRC Imaging System",
|
||||||
"AuthorizationCode": "SHzyyl2021",
|
"AuthorizationCode": "SHzyyl2021",
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,8 @@ public class SystemEmailSendConfig
|
||||||
public int Port { get; set; }
|
public int Port { get; set; }
|
||||||
|
|
||||||
public string Host { get; set; } = string.Empty;
|
public string Host { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Imap { get; set; } = string.Empty;
|
||||||
public string FromEmail { get; set; } = string.Empty;
|
public string FromEmail { get; set; } = string.Empty;
|
||||||
|
|
||||||
public string FromName { get; set; } = string.Empty;
|
public string FromName { get; set; } = string.Empty;
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ using IRaCIS.Core.Domain.Share;
|
||||||
using MailKit;
|
using MailKit;
|
||||||
using MailKit.Net.Imap;
|
using MailKit.Net.Imap;
|
||||||
using MailKit.Search;
|
using MailKit.Search;
|
||||||
|
using MailKit.Security;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using NPOI.SS.Formula.Functions;
|
using NPOI.SS.Formula.Functions;
|
||||||
|
|
@ -41,34 +42,53 @@ namespace IRaCIS.Core.Application.Contracts
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
using var client = new ImapClient();
|
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<object> list= new List<object>();
|
|
||||||
for (int i = 0; i < sent.Count; i++)
|
|
||||||
{
|
{
|
||||||
var msg = await sent.GetMessageAsync(i);
|
|
||||||
list.Add(new {
|
|
||||||
Subject= msg.Subject,
|
try
|
||||||
From= msg.From.ToString(),
|
{
|
||||||
To = msg.To.ToString(),
|
// 连接阿里邮箱 IMAP 服务器(使用 SSL)
|
||||||
TextBody = msg.TextBody ?? "",
|
client.Connect(_systemEmailConfig.Imap, 993, SecureSocketOptions.SslOnConnect);
|
||||||
HtmlBody = msg.HtmlBody ?? "",
|
|
||||||
Date = msg.Date.UtcDateTime
|
// 登录
|
||||||
});
|
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 true;
|
||||||
return list;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue