Beispiel #1
0
        public MailContentData CreateSummaryEmailAlertMessage(ParseEmailParam param, ILogger logger)
        {
            var mailData = new MailContentData();

            mailData.MailInfo = new MailInfo();

            if (param.Recipients == null && !param.Recipients.Any())
            {
                throw new ArgumentNullException(RecipientNullErrorMessage);
            }

            mailData.MailInfo.Recipients  = param.Recipients;
            mailData.MailInfo.Subject     = _temperatureFilterConfiguration.Subject;
            mailData.MailInfo.ContentBody = ApplyTextReplacement(_temperatureFilterConfiguration.EmailTemplate, param);
            mailData.MailInfo.Sender      = _temperatureFilterConfiguration.Sender;
            mailData.MailInfo.SenderName  = _temperatureFilterConfiguration.SenderName;

            return(mailData);
        }
Beispiel #2
0
        public MailContentData CreateTemperatureEmailAlertMessage(EmailTemperatureHitParameter infoParameter, ILogger logger)
        {
            var mailData = new MailContentData();

            mailData.MailInfo = new MailInfo();

            logger.LogInformation("Getting sender/recipient email address.");
            var recipients = GetEmailAddress(infoParameter.DeviceId);

            if (recipients == null)
            {
                throw new ArgumentNullException("Recipients is null, please ensure recipient are setup properly.");
            }

            mailData.MailInfo.Recipients  = recipients;
            mailData.MailInfo.Subject     = _temperatureFilterConfiguration.Subject;
            mailData.MailInfo.ContentBody = ApplyTextReplacement(infoParameter);
            mailData.MailInfo.Sender      = _temperatureFilterConfiguration.Sender;
            mailData.MailInfo.SenderName  = _temperatureFilterConfiguration.SenderName;
            return(mailData);
        }
        public async Task SendMailAsync(MailContentData record, ILogger logger)
        {
            logger.LogInformation($"Sending email. {DateTime.Now}");

            var senderAddress = new EmailAddress(record.MailInfo.Sender, record.MailInfo.SenderName);

            List <EmailAddress> recipientsList = new List <EmailAddress>();

            foreach (var recipient in record.MailInfo.Recipients)
            {
                recipientsList.Add(new EmailAddress(recipient));
            }

            var subject           = record.MailInfo.Subject;
            var htmlContent       = record.MailInfo.ContentBody;
            var displayRecipients = false;

            var mssage = MailHelper.CreateSingleEmailToMultipleRecipients(senderAddress, recipientsList,
                                                                          subject, string.Empty, htmlContent, displayRecipients);

            var response = await _client.SendEmailAsync(mssage);

            logger.LogInformation($"Mail message sent result {response.StatusCode} at {DateTime.Now}");
        }