public override void Handle(SendMeasurementsCommand command) { var measurements = Repository.Where( new CommonSpecification <MeterMeasurement>( x => command.MeterMeasurementIdentifiers.Contains(x.Id))) .ToList(); var isAllMeasurementsInOneMonth = CheckIsAllMeasurementsInOneMonth(measurements); if (!isAllMeasurementsInOneMonth) { throw new Exception("Selected measurements isn't for one month"); } var mappedMeasurements = measurements.Select(x => $"{x.MeasurementType.Name}: {x.Measurement}"); var date = measurements.FirstOrDefault().Date.ToString("MMMM yyyy", CultureInfo.GetCultureInfo("ru-RU")); var messageModel = new MeasurementMailModel(date, string.Join("\n", mappedMeasurements)); MailProcessor.Send(new SendMeasurementsMail(command.Recipient, date, messageModel)); foreach (var measurement in measurements) { measurement.IsSent = true; } }
public void TestMailMessage([FromBody] TestMailMessageRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var isValidEmail = Validate.Email(request.Recipient); if (!isValidEmail) { throw new ArgumentException($"Passed \"{request.Recipient}\" isn't recognized as email."); } MailProcessor.Send(new TestMailMessage(request.Recipient)); }
/// <summary> /// 寄送郵件 /// </summary> /// <param name="_MailServer">郵件主機位置</param> /// <param name="_MailServerPort">郵件主機服務Port</param> /// <param name="_MailSender">寄件者</param> /// <param name="_MailReceivers">收件者清單</param> /// <returns></returns> /// <remarks></remarks> public string SendEmail(string _MailServer, int _MailServerPort, string _MailSender, List<string> _MailReceivers, string _Subject, string _Body) { string SendResult = null; MailProcessor MailP = new MailProcessor(); string MailServer = _MailServer; int MailServerPort = _MailServerPort; string MailSender = _MailSender; List<string> MailReceivers = _MailReceivers; string MailSubject = _Subject; string SendBody = _Body; List<System.Net.Mail.Attachment> MailA = new List<System.Net.Mail.Attachment>(); List<string> MailCC = new List<string>(); MailP.setMailProcossor(MailSender, MailReceivers, MailCC, MailSubject, SendBody, MailA, MailServer, MailServerPort, false, true, MailPriority.High.ToString(), 65001); SendResult = MailP.Send(); return SendResult; }