mirror of
https://github.com/morbalint/kemkas.git
synced 2026-07-18 03:13:46 +00:00
adding hidden basic asp.net core backend (#30)
Base functionality:
DB
email sending
user registration & login
storing new characters and reading them back
Notes:
Functionality is "hidden" with no links pointing to it.
Most pages are scaffolded and not reviewed at all :(
local Dev db setup is pushed to git
NO local email setup :(
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using System.Net.Http.Headers;
|
||||
using Kemkas.Web.Config;
|
||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Kemkas.Web.Services.Identity;
|
||||
|
||||
public class MailgunEmailSender(IOptions<MailgunOptions> sendGridOptions, HttpClient httpClient) : IEmailSender
|
||||
{
|
||||
public async Task SendEmailAsync(string email, string subject, string htmlMessage)
|
||||
{
|
||||
var domain = sendGridOptions.Value.DomainName;
|
||||
var uri = new Uri($"https://api.eu.mailgun.net/v3/{domain}/messages");
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, uri);
|
||||
var authHeaderValue = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"api:{sendGridOptions.Value.ApiKey}"));
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Basic", authHeaderValue);
|
||||
|
||||
request.Content = new FormUrlEncodedContent(
|
||||
[
|
||||
new KeyValuePair<string,string>("from", $"no-reply@{domain}"),
|
||||
new KeyValuePair<string,string>("to", email),
|
||||
new KeyValuePair<string,string>("subject", subject),
|
||||
new KeyValuePair<string,string>("html", htmlMessage),
|
||||
]);
|
||||
|
||||
var response = await httpClient.SendAsync(request);
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user