open changes
This commit is contained in:
50
wishlist/Data/EmailSender.cs
Normal file
50
wishlist/Data/EmailSender.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||
using System.Net.Mail;
|
||||
using System.Text;
|
||||
|
||||
namespace Wishlist.Data;
|
||||
|
||||
public class EmailSender : IEmailSender
|
||||
{
|
||||
private ILogger<EmailSender> _logger;
|
||||
|
||||
public EmailSender(ILogger<EmailSender> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Task SendEmailAsync(string email, string subject, string htmlMessage)
|
||||
{
|
||||
_logger.LogInformation("Email sender started.");
|
||||
|
||||
string host = "wishlist.arnemoerman.be";
|
||||
string from = "wishlist@arnemoerman.be";
|
||||
int port = 25;
|
||||
bool enableSsl = false;
|
||||
|
||||
MailMessage message = new(from, email, subject, htmlMessage)
|
||||
{
|
||||
HeadersEncoding = Encoding.UTF8,
|
||||
SubjectEncoding = Encoding.UTF8,
|
||||
BodyEncoding = Encoding.UTF8,
|
||||
IsBodyHtml = true
|
||||
};
|
||||
|
||||
using (var smtp = new SmtpClient(host))
|
||||
{
|
||||
smtp.Port = port;
|
||||
smtp.EnableSsl = enableSsl;
|
||||
|
||||
try
|
||||
{
|
||||
smtp.Send(message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogCritical(ex, "Sending Email Error");
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user