Example #1
0
        private static async Task SendSuccessMailInternal([NotNull] string description, [NotNull] string message, TimeSpan duration)
        {
            var    errors         = EventSourceRegistrar.GetSessionErrors();
            var    eventFormatter = new EventTextFormatter();
            string errorsText;

            using (var writer = new StringWriter())
            {
                foreach (var error in errors)
                {
                    eventFormatter.WriteEvent(error, writer);
                }
                errorsText = writer.ToString();
            }

            CommonEventSource.Log.SendSuccessMailStart(description);

            var from    = new EmailAddress("*****@*****.**", "HLTBS webjobs");
            var to      = new EmailAddress("*****@*****.**", "HLTBS contact");
            var subject = String.Format(CultureInfo.InvariantCulture, "{0} - Success ({1}) [{2}]",
                                        WebJobName, duration, message + (errors.Length == 0 ? String.Empty : " (with session errors)"));
            var text = String.Format(CultureInfo.InvariantCulture, "{1}{0}Run ID: {2}{0}Start time: {3}{0}End time:{4}{0}Output log file: {5}{6}",
                                     Environment.NewLine, GetTriggeredRunUrl(), WebJobRunId, DateTime.UtcNow - duration, DateTime.UtcNow, GetTriggeredLogUrl(),
                                     errors.Length == 0 ? String.Empty : String.Format("{0}Session Errors:{0}{1}", Environment.NewLine, errorsText));
            var mail = MailHelper.CreateSingleEmail(from, to, subject, text, null);

            using (var response = await SendGridClient.PostAsJsonAsync <SendGridMessage, string>(SendGridApiSendAddress, mail))
            {
                CommonEventSource.Log.SendSuccessMailStop(
                    description, response.ResponseMessage.StatusCode, response.ResponseMessage.Headers.ToString(), response.Content);
            }
        }