邮件代码提交
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
456793293b
commit
ca679057c4
|
|
@ -23,9 +23,9 @@ public class EmailLogAddOrEdit
|
||||||
{
|
{
|
||||||
public Guid? Id { get; set; }
|
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; }
|
public DateTime? EmailDate { get; set; }
|
||||||
|
|
||||||
|
|
@ -39,16 +39,16 @@ public class EmailLogAddOrEdit
|
||||||
|
|
||||||
public string SenderAddress { get; set; }
|
public string SenderAddress { get; set; }
|
||||||
|
|
||||||
public List`1 ToRecipients { get; set; }
|
public string ToRecipients { get; set; }
|
||||||
|
|
||||||
public string UniqueId { get; set; }
|
public string UniqueId { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EmailLogQuery:PageInput
|
public class EmailLogQuery:PageInput
|
||||||
{
|
{
|
||||||
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; }
|
public DateTime? EmailDate { get; set; }
|
||||||
|
|
||||||
|
|
@ -62,7 +62,7 @@ public class EmailLogQuery:PageInput
|
||||||
|
|
||||||
public string? SenderAddress { get; set; }
|
public string? SenderAddress { get; set; }
|
||||||
|
|
||||||
public List`1? ToRecipients { get; set; }
|
public string ToRecipients { get; set; }
|
||||||
|
|
||||||
public string? UniqueId { get; set; }
|
public string? UniqueId { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,26 +4,84 @@
|
||||||
// 生成时间 2025-10-28 06:22:42Z
|
// 生成时间 2025-10-28 06:22:42Z
|
||||||
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
using IRaCIS.Core.Domain.Models;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using IRaCIS.Core.Application.Interfaces;
|
using IRaCIS.Core.Application.Interfaces;
|
||||||
using IRaCIS.Core.Application.ViewModel;
|
using IRaCIS.Core.Application.ViewModel;
|
||||||
using IRaCIS.Core.Infrastructure.Extention;
|
using IRaCIS.Core.Domain.Models;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using IRaCIS.Core.Infra.EFCore;
|
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;
|
namespace IRaCIS.Core.Application.Service;
|
||||||
|
|
||||||
[ ApiExplorerSettings(GroupName = "Test")]
|
[ ApiExplorerSettings(GroupName = "Test")]
|
||||||
public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
|
public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
|
||||||
|
IOptionsMonitor<SystemEmailSendConfig> systemEmailConfig,
|
||||||
IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer): BaseService, IEmailLogService
|
IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer): BaseService, IEmailLogService
|
||||||
{
|
{
|
||||||
|
private readonly SystemEmailSendConfig _systemEmailConfig = systemEmailConfig.CurrentValue;
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
[HttpPost]
|
|
||||||
public async Task<PageOutput<EmailLogView>> GetEmailLogList(EmailLogQuery inQuery)
|
public async Task<PageOutput<EmailLogView>> GetEmailLogList(EmailLogQuery inQuery)
|
||||||
{
|
{
|
||||||
|
|
||||||
var emailLogQueryable =_emailLogRepository
|
List<IMessageSummary> emailList = new List<IMessageSummary>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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<EmailLogView>(_mapper.ConfigurationProvider);
|
.ProjectTo<EmailLogView>(_mapper.ConfigurationProvider);
|
||||||
|
|
||||||
var pageList= await emailLogQueryable.ToPagedListAsync(inQuery);
|
var pageList= await emailLogQueryable.ToPagedListAsync(inQuery);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue