blob: e5ef97cd0e7e16d52f533c07c3fa02f0ed05ce1b (
plain) (
blame)
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.Net;
using System.Net.Mail;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
namespace Dough.Services
{
public class EmailService
{
private readonly IConfiguration _configuration;
public EmailService(IConfiguration configuration)
{
_configuration = configuration;
}
public async Task<bool> Send(string subject, string message, string recepient)
{
var smtpPassword = _configuration.GetValue<string>("SMTP_PASSWORD");
var smtpUser = _configuration.GetValue<string>("SMTP_USER");
var smtpHost = _configuration.GetValue<string>("SMTP_HOST");
var smtpClient = new SmtpClient
{
Credentials = new NetworkCredential
{
UserName = smtpUser,
Password = smtpPassword,
Domain = smtpHost
},
Host = smtpHost
};
await smtpClient.SendMailAsync(smtpUser, recepient, subject, message);
return true;
}
}
}
|