|
|
@ -62,22 +62,6 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
|
|
|
|
ArgumentNullException.ThrowIfNull(mailConfig, nameof(mailConfig));
|
|
|
|
ArgumentNullException.ThrowIfNull(mailConfig, nameof(mailConfig));
|
|
|
|
ArgumentNullException.ThrowIfNull(templateModel, nameof(templateModel));
|
|
|
|
ArgumentNullException.ThrowIfNull(templateModel, nameof(templateModel));
|
|
|
|
|
|
|
|
|
|
|
|
string title, content = string.Empty;
|
|
|
|
|
|
|
|
var razorEngine = new RazorEngine();
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string key1 = mailConfig.Id + "-" + nameof(mailConfig.Title);
|
|
|
|
|
|
|
|
title = await RenderTemplateAsync(key1, mailConfig.Title, templateModel, razorEngine);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string key2 = mailConfig.Id + "-" + nameof(mailConfig.Content);
|
|
|
|
|
|
|
|
content = await RenderTemplateAsync(key2, mailConfig.Content, templateModel, razorEngine);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await ex.LogAsync(Db);
|
|
|
|
|
|
|
|
return DataResult.Failed($"渲染邮件模板({mailConfig.Id})时出错,请检查模板是否有语法错误");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var order = await TenantDb.Queryable<SeaExport>().Where(x => x.Id == templateModel.BusinessId)
|
|
|
|
var order = await TenantDb.Queryable<SeaExport>().Where(x => x.Id == templateModel.BusinessId)
|
|
|
|
.Select(x => new
|
|
|
|
.Select(x => new
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -108,27 +92,17 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
|
|
|
|
else if (mailConfig.Sender.IsVouchingClerk)
|
|
|
|
else if (mailConfig.Sender.IsVouchingClerk)
|
|
|
|
senderId = order.Doc;
|
|
|
|
senderId = order.Doc;
|
|
|
|
|
|
|
|
|
|
|
|
var sender = await Db.Queryable<SysUser>().Where(x => x.Id == senderId).Select(x => new { x.UserName, x.SignatureHtml }).FirstAsync();
|
|
|
|
templateModel.Sender = await Db.Queryable<SysUser>().Where(x => x.Id == senderId).Select(x => new MailSender
|
|
|
|
if (sender == null)
|
|
|
|
{
|
|
|
|
|
|
|
|
DisplayName = x.UserName,
|
|
|
|
|
|
|
|
SignatureHtml = x.SignatureHtml
|
|
|
|
|
|
|
|
}).FirstAsync();
|
|
|
|
|
|
|
|
if (templateModel.Sender == null)
|
|
|
|
return DataResult.Failed("未设置发件人");
|
|
|
|
return DataResult.Failed("未设置发件人");
|
|
|
|
|
|
|
|
|
|
|
|
var senderConfig = await TenantDb.Queryable<CodeUserEmail>().FirstAsync(x => x.CreateBy == senderId);
|
|
|
|
var senderConfig = await TenantDb.Queryable<CodeUserEmail>().FirstAsync(x => x.CreateBy == senderId);
|
|
|
|
if (senderConfig == null)
|
|
|
|
if (senderConfig == null)
|
|
|
|
return DataResult.Failed($"发件人用户:{sender.UserName} 未设置SMTP发件信息");
|
|
|
|
return DataResult.Failed($"发件人用户:{templateModel.Sender.DisplayName} 未设置SMTP发件信息");
|
|
|
|
|
|
|
|
|
|
|
|
//插入发件人签名
|
|
|
|
|
|
|
|
var htmlDoc = new HtmlDocument();
|
|
|
|
|
|
|
|
htmlDoc.LoadHtml(content);
|
|
|
|
|
|
|
|
var node = htmlDoc.GetElementbyId("sign");
|
|
|
|
|
|
|
|
if (node != null)
|
|
|
|
|
|
|
|
node.InnerHtml = sender.SignatureHtml;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (StringWriter writer = new())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
htmlDoc.Save(writer);
|
|
|
|
|
|
|
|
content = writer.ToString();
|
|
|
|
|
|
|
|
writer.Close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//设置抄送人
|
|
|
|
//设置抄送人
|
|
|
|
List<long> ccIds = [];
|
|
|
|
List<long> ccIds = [];
|
|
|
@ -162,9 +136,39 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
|
|
|
|
if (mailConfig.Receiver.IsController)
|
|
|
|
if (mailConfig.Receiver.IsController)
|
|
|
|
receiverTypes.Add("controller");
|
|
|
|
receiverTypes.Add("controller");
|
|
|
|
|
|
|
|
|
|
|
|
var receiverList = await TenantDb.Queryable<BusinessOrderContact>().Where(x => receiverTypes.Contains(x.CustomerType)
|
|
|
|
templateModel.Receivers = await TenantDb.Queryable<BusinessOrderContact>().Where(x => receiverTypes.Contains(x.CustomerType)
|
|
|
|
&& x.Email != null && x.Email != string.Empty && x.BusinessId == templateModel.BusinessId && x.BusinessType == templateModel.BusinessType)
|
|
|
|
&& x.Email != null && x.Email != string.Empty && x.BusinessId == templateModel.BusinessId && x.BusinessType == templateModel.BusinessType)
|
|
|
|
.Select(x => new { x.Name, x.Email }).ToListAsync();
|
|
|
|
.Select(x => new MailReceiver { DisplayName = x.Name, MailAddress = x.Email }).ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string title, content = string.Empty;
|
|
|
|
|
|
|
|
var razorEngine = new RazorEngine();
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string key1 = mailConfig.Id + "-" + nameof(mailConfig.Title);
|
|
|
|
|
|
|
|
title = await RenderTemplateAsync(key1, mailConfig.Title, templateModel, razorEngine);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string key2 = mailConfig.Id + "-" + nameof(mailConfig.Content);
|
|
|
|
|
|
|
|
content = await RenderTemplateAsync(key2, mailConfig.Content, templateModel, razorEngine);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await ex.LogAsync(Db);
|
|
|
|
|
|
|
|
return DataResult.Failed($"渲染邮件模板({mailConfig.Id})时出错,请检查模板是否有语法错误");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//插入发件人签名
|
|
|
|
|
|
|
|
var htmlDoc = new HtmlDocument();
|
|
|
|
|
|
|
|
htmlDoc.LoadHtml(content);
|
|
|
|
|
|
|
|
var node = htmlDoc.GetElementbyId("sign");
|
|
|
|
|
|
|
|
if (node != null)
|
|
|
|
|
|
|
|
node.InnerHtml = templateModel.Sender.SignatureHtml;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (StringWriter writer = new())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
htmlDoc.Save(writer);
|
|
|
|
|
|
|
|
content = writer.ToString();
|
|
|
|
|
|
|
|
writer.Close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var attachmentList = mailConfig.Attachments == null ? [] : new List<Tuple<string, string>>(mailConfig.Attachments.Count);
|
|
|
|
var attachmentList = mailConfig.Attachments == null ? [] : new List<Tuple<string, string>>(mailConfig.Attachments.Count);
|
|
|
|
try
|
|
|
|
try
|
|
|
@ -222,13 +226,14 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string sendTo = string.Join(",", templateModel.Receivers.Select(x => x.MailAddress));
|
|
|
|
dynamic[] mailParams = [new
|
|
|
|
dynamic[] mailParams = [new
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SendTo = string.Join(",", receiverList.Select(x => x.Email)),
|
|
|
|
SendTo = sendTo,
|
|
|
|
Title = title,
|
|
|
|
Title = title,
|
|
|
|
Body = content,
|
|
|
|
Body = content,
|
|
|
|
CCTo = string.Join(",", ccList),
|
|
|
|
CCTo = string.Join(",", ccList),
|
|
|
|
ShowName = senderConfig.ShowName.IsNullOrEmpty() ? sender.UserName : senderConfig.ShowName,
|
|
|
|
ShowName = senderConfig.ShowName.IsNullOrEmpty() ? templateModel.Sender.DisplayName : senderConfig.ShowName,
|
|
|
|
Account = senderConfig.MailAccount,
|
|
|
|
Account = senderConfig.MailAccount,
|
|
|
|
senderConfig.Password,
|
|
|
|
senderConfig.Password,
|
|
|
|
Server = senderConfig.SmtpServer,
|
|
|
|
Server = senderConfig.SmtpServer,
|
|
|
@ -245,11 +250,11 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
|
|
|
|
if (mailResult.Data.IsSuccessStatusCode)
|
|
|
|
if (mailResult.Data.IsSuccessStatusCode)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return DataResult.Successed($"已发邮件(委托单:{order.CustomerNo}),收件人:"
|
|
|
|
return DataResult.Successed($"已发邮件(委托单:{order.CustomerNo}),收件人:"
|
|
|
|
+ string.Join(",", receiverList.Select(x => x.Email)) + "发件人:" + senderConfig.MailAccount);
|
|
|
|
+ string.Join(",", sendTo) + "发件人:" + senderConfig.MailAccount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult.Failed($"邮件发送失败,API返回状态为:{(int)mailResult.Data.StatusCode} {mailResult.Data.StatusCode}"
|
|
|
|
return DataResult.Failed($"邮件发送失败,API返回状态为:{(int)mailResult.Data.StatusCode} {mailResult.Data.StatusCode}"
|
|
|
|
+ $"(委托单:{order.CustomerNo}),收件人:" + string.Join(",", receiverList.Select(x => x.Email)) + "发件人:" + senderConfig.MailAccount);
|
|
|
|
+ $"(委托单:{order.CustomerNo}),收件人:" + string.Join(",", sendTo) + "发件人:" + senderConfig.MailAccount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|