using FluentFTP; using YLErp.MailKit; using YLErp.Modules.AppModule; namespace YLErp.Helpers { /// /// 邮件发送帮助类 /// public class EmailHelper { static readonly Dictionary _dic; static EmailHelper() { _dic = new Dictionary(StringComparer.OrdinalIgnoreCase); } public static string SendMailOfTradeConfirmBook(string mailTo, IEnumerable filesToAttach, string title, string body, bool isHtml = false) { if (string.IsNullOrWhiteSpace(title)) { title = "交易确认书"; } if (string.IsNullOrWhiteSpace(body)) { body = "请查看附件交易确认书"; } try { return SendMail(mailTo, title, body, isHtml, filesToAttach); } catch (Exception ex) { LogFactory.GetLogger().Error("邮件发送失败:" + title, ex); return ex.Message; } } public static string SendMail(string mailTo, string subject, string body, bool isBodyHtml = true, IEnumerable filesToAttach = null, string ccEmail = null, string mailFrom = null) { if (string.IsNullOrEmpty(mailTo)) { throw new ArgumentException("不能为空", nameof(mailTo)); } return doSendMail(mailTo, subject, body, isBodyHtml, filesToAttach, ccEmail); } private static string doSendMail( string mailTo, string subject, string body, bool isBodyHtml, IEnumerable filesToAttach, string ccEmail) { try { //去重 var toSet = mailTo.Split(new[] { ';', ',', ',' }, StringSplitOptions.RemoveEmptyEntries) .ToHashSet(StringComparer.OrdinalIgnoreCase); var mailToArr = toSet.ToArray(); MailSender.SendApi(new MailSendingOption { MailTo = mailToArr, Subject = subject, Body = body, IsBodyHtml = isBodyHtml, FilesToAttach = filesToAttach, CC = ccEmail }); return string.Empty; } catch (Exception ex) { LogFactory.GetLogger("邮件发送").Error("邮件发送失败:" + subject, ex); return ex.Message; } } } }