@@ -157,6 +157,42 @@ namespace IRaCIS.Core.Application.Contracts
|
|||||||
public string EmailTopicCN { get; set; } = string.Empty;
|
public string EmailTopicCN { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 手动发送项目邮件请求参数
|
||||||
|
/// </summary>
|
||||||
|
public class ManualSendEmailCommand
|
||||||
|
{
|
||||||
|
[NotDefault]
|
||||||
|
public Guid TrialId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 收件人邮箱列表
|
||||||
|
/// </summary>
|
||||||
|
public List<EmailRecipientCommand> ToEmailList { get; set; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 抄送人邮箱列表
|
||||||
|
/// </summary>
|
||||||
|
public List<EmailRecipientCommand> CcEmailList { get; set; } = new();
|
||||||
|
|
||||||
|
public string Subject { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 邮件 HTML 内容
|
||||||
|
/// </summary>
|
||||||
|
public string Content { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 邮件收件人信息
|
||||||
|
/// </summary>
|
||||||
|
public class EmailRecipientCommand
|
||||||
|
{
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string EmailAddress { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public class EmailNoticeConfigExportDto
|
public class EmailNoticeConfigExportDto
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ using MailKit.Search;
|
|||||||
using MailKit.Security;
|
using MailKit.Security;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
using MimeKit;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace IRaCIS.Core.Application.Contracts
|
namespace IRaCIS.Core.Application.Contracts
|
||||||
@@ -21,11 +22,47 @@ namespace IRaCIS.Core.Application.Contracts
|
|||||||
[ApiExplorerSettings(GroupName = "Common")]
|
[ApiExplorerSettings(GroupName = "Common")]
|
||||||
public class EmailNoticeConfigService(IRepository<EmailNoticeConfig> _emailNoticeConfigrepository,
|
public class EmailNoticeConfigService(IRepository<EmailNoticeConfig> _emailNoticeConfigrepository,
|
||||||
IRepository<EmailNoticeUserType> _emailNoticeUserTypeRepository,
|
IRepository<EmailNoticeUserType> _emailNoticeUserTypeRepository,
|
||||||
|
IRepository<Trial> _trialRepository,
|
||||||
IOptionsMonitor<SystemEmailSendConfig> systemEmailConfig,
|
IOptionsMonitor<SystemEmailSendConfig> systemEmailConfig,
|
||||||
IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer) : BaseService, IEmailNoticeConfigService
|
IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer) : BaseService, IEmailNoticeConfigService
|
||||||
{
|
{
|
||||||
private readonly SystemEmailSendConfig _systemEmailConfig = systemEmailConfig.CurrentValue;
|
private readonly SystemEmailSendConfig _systemEmailConfig = systemEmailConfig.CurrentValue;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据项目邮件配置手动发送邮件
|
||||||
|
/// </summary>
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<IResponseOutput> ManualSendEmail(ManualSendEmailCommand inDto)
|
||||||
|
{
|
||||||
|
var trial = await _trialRepository.Where(t => t.Id == inDto.TrialId).FirstNotNullAsync();
|
||||||
|
|
||||||
|
var messageToSend = new MimeMessage
|
||||||
|
{
|
||||||
|
Subject = inDto.Subject
|
||||||
|
};
|
||||||
|
|
||||||
|
messageToSend.From.Add(new MailboxAddress(trial.EmailFromName, trial.EmailFromEmail));
|
||||||
|
|
||||||
|
foreach (var recipient in inDto.ToEmailList.Where(t => !string.IsNullOrWhiteSpace(t.EmailAddress)))
|
||||||
|
{
|
||||||
|
messageToSend.To.Add(new MailboxAddress(recipient.Name, recipient.EmailAddress));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var recipient in inDto.CcEmailList.Where(t => !string.IsNullOrWhiteSpace(t.EmailAddress)))
|
||||||
|
{
|
||||||
|
messageToSend.Cc.Add(new MailboxAddress(recipient.Name, recipient.EmailAddress));
|
||||||
|
}
|
||||||
|
|
||||||
|
messageToSend.Body = new BodyBuilder
|
||||||
|
{
|
||||||
|
HtmlBody = inDto.Content
|
||||||
|
}.ToMessageBody();
|
||||||
|
|
||||||
|
await SendEmailHelper.SendTrialEmailAsync(messageToSend, trial);
|
||||||
|
|
||||||
|
return ResponseOutput.Ok();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取邮件列表
|
/// 获取邮件列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -11,5 +11,6 @@ namespace IRaCIS.Core.Application.Contracts
|
|||||||
Task<IResponseOutput> AddOrUpdateEmailNoticeConfig(EmailNoticeConfigAddOrEdit addOrEditEmailNoticeConfig);
|
Task<IResponseOutput> AddOrUpdateEmailNoticeConfig(EmailNoticeConfigAddOrEdit addOrEditEmailNoticeConfig);
|
||||||
Task<IResponseOutput> DeleteEmailNoticeConfig(Guid emailNoticeConfigId);
|
Task<IResponseOutput> DeleteEmailNoticeConfig(Guid emailNoticeConfigId);
|
||||||
Task<PageOutput<EmailNoticeConfigView>> GetEmailNoticeConfigList(EmailNoticeConfigQuery queryEmailNoticeConfig);
|
Task<PageOutput<EmailNoticeConfigView>> GetEmailNoticeConfigList(EmailNoticeConfigQuery queryEmailNoticeConfig);
|
||||||
|
Task<IResponseOutput> ManualSendEmail(ManualSendEmailCommand inDto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user