-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmailSender.cs
37 lines (32 loc) · 1.14 KB
/
EmailSender.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity.UI.Services;
using RestSharp;
using RestSharp.Authenticators;
namespace VLO_BOARDS;
public class EmailSender : IEmailSender
{
private readonly MailgunConfig _config;
public EmailSender(MailgunConfig config)
{
_config = config;
}
public Task SendEmailAsync(string email, string subject, string htmlMessage)
{
RestClient client = new RestClient ("https://api.eu.mailgun.net/v3");
client.Authenticator = new HttpBasicAuthenticator ("api",_config.ApiKey);
RestRequest request = new RestRequest();
request.AddParameter ("domain", _config.DomainName, ParameterType.UrlSegment);
request.Resource = "{domain}/messages";
request.AddParameter ("from", $"noreply <noreply@{_config.DomainName}>");
request.AddParameter ("to", email);
request.AddParameter ("subject", subject);
request.AddParameter ("html", htmlMessage);
return client.PostAsync(request);
}
}
public class MailgunConfig
{
public string ApiKey { get; set; }
public string DomainName { get; set; }
}