50 lines
1.2 KiB
C#
50 lines
1.2 KiB
C#
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;
|
|
}
|
|
} |