Created
April 13, 2017 20:27
-
-
Save jeancroy/81397ac4417e2543ce763bd2e8ec706c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class SendGridDeliveryServices | |
{ | |
private static string _sendGridApiKey = "..."; | |
public static bool SendMailToCustomerServices(string name, string email, string subject, string body) | |
{ | |
var from = new EmailAddress("system@xyz.com", name); | |
var reply = new EmailAddress(email, name); | |
var to = new EmailAddress("hello@xyz.com"); | |
var mail = new SendGridMessage() | |
{ | |
From = from, | |
Subject = subject, | |
PlainTextContent = body, | |
}; | |
mail.AddTo(to); | |
mail.ReplyTo = reply; | |
return PostMail(mail).Result; | |
} | |
public static async Task<bool> PostMail(SendGridMessage mail) | |
{ | |
var client = new SendGridClient(_sendGridApiKey); | |
var response = await client.SendEmailAsync(mail); // This line hang indefinitively | |
//Success | |
if (response.StatusCode == System.Net.HttpStatusCode.Accepted || response.StatusCode == System.Net.HttpStatusCode.OK) | |
return true; | |
//Error, get message to log it. | |
// var responseBody = response.Body.ReadAsStringAsync().Result; | |
// logger.log(responseBody); | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment