Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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