示例#1
0
        public async Task Send(SendSimpleEmailToRecipient message)
        {
            if (message == null)
            {
                this._logger.LogWarning("Asked to send a null message. Will not be sending anything.");
                return;
            }

            var messageBusCts     = new CancellationTokenSource(TimeSpan.FromMinutes(10));
            var serialisedMessage = this._serialiser.Serialise(message);

            try
            {
                this._logger.LogInformation($"Dispatching to {this._awsConfiguration.EmailServiceSendEmailQueueName}");
                await this._awsQueueClient.SendToQueue(
                    this._awsConfiguration.EmailServiceSendEmailQueueName,
                    serialisedMessage,
                    messageBusCts.Token);

                this._logger.LogInformation(
                    $"Finished dispatching to {this._awsConfiguration.EmailServiceSendEmailQueueName}");
            }
            catch (Exception e)
            {
                this._logger.LogError(e, $"Exception sending message '{serialisedMessage}' to bus on queue {this._awsConfiguration.EmailServiceSendEmailQueueName}.");
            }
        }
        private void DispatchEmail(string errorBody)
        {
            var preamble =
                $"Uploaded file for surveillance received at {DateTime.UtcNow} (UTC) had validation errors. The file will not be processed until these errors are addressed. {Environment.NewLine} {Environment.NewLine}";
            var htmlTaggedPreamble = this.HtmlTagEnvironmentNewLines(preamble);

            var errorMessage = $"{htmlTaggedPreamble} {errorBody}";

            this.Logger.LogError(errorMessage);

            var trimmedTargets = this._configuration.DataImportEtlFailureNotifications.Split(',')
                                 .Where(i => !string.IsNullOrWhiteSpace(i)).Select(y => y.Trim()).ToList();

            if (!trimmedTargets.Any())
            {
                this.Logger.LogInformation(
                    $"No ETL notification targets set {this._configuration.DataImportEtlFailureNotifications}");
                return;
            }

            var message = new SendSimpleEmailToRecipient
            {
                Subject = "Surveillance File Validation",
                Message = errorMessage,
                OverrideDefaultFromAddress = false,
                ToAddresses = trimmedTargets,
                IsHtml      = true
            };

            this._messageSender.Send(message);
        }