aboutsummaryrefslogtreecommitdiffstats
path: root/src/server/Services/EmailService.cs
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2020-08-10 21:35:58 +0200
committerivarlovlie <git@ivarlovlie.no>2020-08-10 21:35:58 +0200
commit2cfee78597971b2e3e7e612eb9d7e8805e1aef85 (patch)
treeb939d48347c7fff48d2a51761cb546c3b9ac6ec0 /src/server/Services/EmailService.cs
parent8614d18522441543e08c37c68121fed1fa8d6ae7 (diff)
downloaddough-2cfee78597971b2e3e7e612eb9d7e8805e1aef85.tar.xz
dough-2cfee78597971b2e3e7e612eb9d7e8805e1aef85.zip
add signing credentials
Diffstat (limited to 'src/server/Services/EmailService.cs')
-rw-r--r--src/server/Services/EmailService.cs35
1 files changed, 17 insertions, 18 deletions
diff --git a/src/server/Services/EmailService.cs b/src/server/Services/EmailService.cs
index 9d795d6..e5ef97c 100644
--- a/src/server/Services/EmailService.cs
+++ b/src/server/Services/EmailService.cs
@@ -1,6 +1,5 @@
-using System;
-using System.Collections.Generic;
-using System.Net.Http;
+using System.Net;
+using System.Net.Mail;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
@@ -15,24 +14,24 @@ namespace Dough.Services
_configuration = configuration;
}
- public async Task<bool> Send(string subject, string email)
+ public async Task<bool> Send(string subject, string message, string recepient)
{
- var password = _configuration.GetValue<string>("");
- var emailUser = _configuration.GetValue<string>("");
- var emailHost = _configuration.GetValue<string>("");
+ var smtpPassword = _configuration.GetValue<string>("SMTP_PASSWORD");
+ var smtpUser = _configuration.GetValue<string>("SMTP_USER");
+ var smtpHost = _configuration.GetValue<string>("SMTP_HOST");
- var httpClient = new HttpClient();
-
- var payload = new FormUrlEncodedContent(new[]
+ var smtpClient = new SmtpClient
{
- new KeyValuePair<string, string>("username", emailUser),
- new KeyValuePair<string, string>("password", password),
- });
-
- var requestUri = new Uri(emailHost);
- var request = await httpClient.PostAsync(requestUri, payload);
-
- return request.IsSuccessStatusCode;
+ Credentials = new NetworkCredential
+ {
+ UserName = smtpUser,
+ Password = smtpPassword,
+ Domain = smtpHost
+ },
+ Host = smtpHost
+ };
+ await smtpClient.SendMailAsync(smtpUser, recepient, subject, message);
+ return true;
}
}
}