Browse Source

邮件优化

SCP_CYJ
qian 6 months ago
parent
commit
0fb97336ff
  1. 2
      Models/ScpEntity/TS_Email.cs
  2. 29
      UniApiGroup/Controller/MailController.cs

2
Models/ScpEntity/TS_Email.cs

@ -20,6 +20,8 @@ namespace CK.SCP.Models.ScpEntity
public int EmailSendState { get; set; }
[DisplayName("ʧ°ÜÔ­Òò")]
public string EmailSendFailReason { get; set; }
[DisplayName("发送时间")]
public string UpdateTime { get; set; }
}
}

29
UniApiGroup/Controller/MailController.cs

@ -182,37 +182,44 @@ namespace CK.SCP.UniApi.Controller
/// </summary>
public static void SendOrderMail()
{
AppBoxContext DB = EntitiesFactory.CreateAppBoxInstance();
ScpEntities SDB = EntitiesFactory.CreateScpInstance();
var emailList = SDB.TS_Email.Where(q => q.EmailSendState == 0).ToList();
try
{
foreach (var item in emailList)
{
try
{
MailManager.SendMailOrders(item.EmailAddress, item.EmailString, "材料订单提醒");
Console.WriteLine($"发送邮件:供应商为{ item.EmailToUser}");
item.EmailSendState = 1;
item.UpdateTime = DateTime.Now.ToString();
}
emailList.ForEach(q =>
catch (Exception ex)
{
q.EmailSendState = 1;
});
item.EmailSendState = 2;
item.EmailSendFailReason = ex.Message;
continue;
}
}
SDB.TS_Email.AddOrUpdate(q => q.UID, emailList.ToArray());
SDB.SaveChanges();
}
catch(Exception ex)
{
emailList.ForEach(q =>
{
q.EmailSendState = 2;
q.EmailSendFailReason = ex.Message;
});
//emailList.ForEach(q =>
//{
// q.EmailSendState = 2;
// q.EmailSendFailReason = ex.Message;
//});
Console.WriteLine(ex.Message);
if (ex.InnerException != null)
{
Console.WriteLine(ex.InnerException.Message);
}
SDB.TS_Email.AddOrUpdate(q => q.UID, emailList.ToArray());
SDB.SaveChanges();
//SDB.TS_Email.AddOrUpdate(q => q.UID, emailList.ToArray());
//SDB.SaveChanges();
}
}

Loading…
Cancel
Save