diff --git a/Entity/EmailMessage.cs b/Entity/EmailMessage.cs index 3390b23..9d72176 100644 --- a/Entity/EmailMessage.cs +++ b/Entity/EmailMessage.cs @@ -32,6 +32,8 @@ public class EmailMessage : BaseEntity /// public DateTime ReceivedDate { get; set; } + public string To { get; set; } = string.Empty; + public string Md5 { get; set; } = string.Empty; public string ComputeBodyHash() diff --git a/Service/EmailBackgroundService.cs b/Service/EmailBackgroundService.cs index 29efd7a..2c952a2 100644 --- a/Service/EmailBackgroundService.cs +++ b/Service/EmailBackgroundService.cs @@ -191,6 +191,7 @@ public class EmailBackgroundService( logger.LogDebug("邮件内容预览: {Preview}", GetEmailBodyPreview(message)); if (await emailHandleService.HandleEmailAsync( + email, message.From.ToString(), message.Subject, message.Date.DateTime, diff --git a/Service/EmailHandleService.cs b/Service/EmailHandleService.cs index fd256d5..1129001 100644 --- a/Service/EmailHandleService.cs +++ b/Service/EmailHandleService.cs @@ -5,6 +5,7 @@ namespace Service; public interface IEmailHandleService { Task HandleEmailAsync( + string to, string from, string subject, DateTime date, @@ -23,6 +24,7 @@ public class EmailHandleService( ) : IEmailHandleService { public async Task HandleEmailAsync( + string to, string from, string subject, DateTime date, @@ -42,7 +44,7 @@ public class EmailHandleService( return false; } - var emailMessage = await SaveEmailAsync(from, subject, date, body); + var emailMessage = await SaveEmailAsync(to, from, subject, date, body); if (emailMessage == null) { @@ -151,6 +153,7 @@ public class EmailHandleService( } private async Task SaveEmailAsync( + string to, string from, string subject, DateTime date, @@ -185,6 +188,9 @@ public class EmailHandleService( } emailEntity.Md5 = emailMd5; + var toName = emailSettings.Value.SmtpList + .FirstOrDefault(s => s.Email == to)?.Name ?? ""; + emailEntity.To = string.IsNullOrEmpty(toName) ? to : $"{toName} <{to}>"; var ok = await emailRepo.AddAsync(emailEntity); if (ok) { diff --git a/Web/src/views/EmailRecord.vue b/Web/src/views/EmailRecord.vue index 0e5031b..261cc3a 100644 --- a/Web/src/views/EmailRecord.vue +++ b/Web/src/views/EmailRecord.vue @@ -35,7 +35,7 @@ > diff --git a/WebApi/Controllers/Dto/EmailMessageDto.cs b/WebApi/Controllers/Dto/EmailMessageDto.cs index a35429d..2990b00 100644 --- a/WebApi/Controllers/Dto/EmailMessageDto.cs +++ b/WebApi/Controllers/Dto/EmailMessageDto.cs @@ -18,6 +18,8 @@ public class EmailMessageDto /// 已解析的账单数量 /// public int TransactionCount { get; set; } + + public string ToName { get; set; } = string.Empty; /// /// 从实体转换为DTO @@ -34,7 +36,8 @@ public class EmailMessageDto ReceivedDate = entity.ReceivedDate, CreateTime = entity.CreateTime, UpdateTime = entity.UpdateTime, - TransactionCount = transactionCount + TransactionCount = transactionCount, + ToName = entity.To?.Split('<').FirstOrDefault()?.Trim() ?? "未知" }; } } diff --git a/WebApi/appsettings.json b/WebApi/appsettings.json index 9997a9f..3459c84 100644 --- a/WebApi/appsettings.json +++ b/WebApi/appsettings.json @@ -42,6 +42,14 @@ "ImapHost": "imap.qq.com", "ImapPort": 993, "UseSsl": true + }, + { + "Name": "SYE", + "Email": "1390853363@qq.com", + "Password": "bmoumfqeyopribec", + "ImapHost": "imap.qq.com", + "ImapPort": 993, + "UseSsl": true } ], "FilterFromAddresses": [