Created
November 20, 2020 19:36
-
-
Save scattered-code/5028076d599ad15e10539fbc2798d9ca to your computer and use it in GitHub Desktop.
This file contains hidden or 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 (var httpClient = new HttpClient()) | |
{ | |
var authToken = Encoding.ASCII.GetBytes($"api:{_emailSettings.Value.ApiKey}"); | |
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(authToken)); | |
var formContent = new FormUrlEncodedContent(new Dictionary<string, string> { | |
{ "from", $"{_emailSettings.Value.DisplayName} <{_emailSettings.Value.From}>" }, | |
{ "h:Reply-To", $"{_emailSettings.Value.DisplayName} <{_emailSettings.Value.ReplyTo}>" }, | |
{ "to", email }, | |
{ "subject", subject }, | |
{ "text", txtMessage }, | |
{ "html", htmlMessage } | |
}); | |
var result = await httpClient.PostAsync($"https://api.mailgun.net/v3/{_emailSettings.Value.EmailDomain}/messages", formContent); | |
result.EnsureSuccessStatusCode(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment