From 2cfee78597971b2e3e7e612eb9d7e8805e1aef85 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Mon, 10 Aug 2020 21:35:58 +0200 Subject: add signing credentials --- src/server/Services/EmailService.cs | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'src/server/Services') 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 Send(string subject, string email) + public async Task Send(string subject, string message, string recepient) { - var password = _configuration.GetValue(""); - var emailUser = _configuration.GetValue(""); - var emailHost = _configuration.GetValue(""); + var smtpPassword = _configuration.GetValue("SMTP_PASSWORD"); + var smtpUser = _configuration.GetValue("SMTP_USER"); + var smtpHost = _configuration.GetValue("SMTP_HOST"); - var httpClient = new HttpClient(); - - var payload = new FormUrlEncodedContent(new[] + var smtpClient = new SmtpClient { - new KeyValuePair("username", emailUser), - new KeyValuePair("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; } } } -- cgit v1.3