Created
March 31, 2016 13:30
-
-
Save ronnieoverby/bdde449e5d1185e74f81001625f6f05f 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
using System.Net.Http; // reference System.Net.Http.dll | |
using System.Net.Http.Headers; | |
using System.Threading.Tasks; | |
public static class MailgunSample | |
{ | |
public static async Task<string> SendSimpleMessageAsync(string domain, string apikey, string from, string to, string subject, string text) | |
{ | |
var authHeader = new AuthenticationHeaderValue("Basic", | |
Convert.ToBase64String(Encoding.ASCII.GetBytes($"api:{apikey}"))); | |
var requestContent = new FormUrlEncodedContent(new Dictionary<string, string> | |
{ | |
["from"] = from, | |
["to"] = to, | |
["subject"] = subject, | |
["text"] = text | |
}); | |
using (var client = new HttpClient()) | |
{ | |
client.BaseAddress = new Uri("https://api.mailgun.net/v3/"); | |
client.DefaultRequestHeaders.Authorization = authHeader; | |
using (var response = await client.PostAsync($"{domain}/messages", requestContent)) | |
return await response.Content.ReadAsStringAsync(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment