static async Task <string> Execute( ExecutionContext context, string msg, dynamic devflag) { SendMailConfig config = new SendMailConfig(context); var apiKey = config.SendGridApiKey; var client = new SendGridClient(apiKey); return(await GetEmailContent(msg, devflag, config, client)); }
private static async Task <string> GetEmailContent( string msg, dynamic devflag, SendMailConfig config, SendGridClient client) { var shldNotSend = devflag.ToString(); var subject = config.EmailSubject; var to = new EmailAddress(config.EmailTo, config.FromName); var from = new EmailAddress(config.EmailFrom, config.ToName); var email = MailHelper.CreateSingleEmail(from, to, subject, msg, ""); if (shldNotSend == "true") { return("success"); } var res = await client.SendEmailAsync(email); if (res.StatusCode != HttpStatusCode.OK && res.StatusCode != HttpStatusCode.Accepted) { throw new ApplicationException("Error sending email " + res.StatusCode); } return(res.StatusCode.ToString()); }