hanyadikhetvan-dotnethf/HanyadikHetVan/Infrastructure/EmailSender.cs

36 lines
1019 B
C#
Raw Permalink Normal View History

2021-05-19 23:14:57 +02:00
using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Threading.Tasks;
namespace HanyadikHetVan.Infrastructure
{
public class EmailSender : IEmailSender
{
private readonly EmailSenderConfig _emailsenderconfig;
public EmailSender(IOptions<EmailSenderConfig> emailsenderconfig)
{
_emailsenderconfig = emailsenderconfig.Value;
}
public Task SendEmailAsync(string email, string subject, string htmlMessage)
{
var client = new SmtpClient(_emailsenderconfig.Host, _emailsenderconfig.Port)
{
UseDefaultCredentials = false,
EnableSsl = false
};
return client.SendMailAsync(
new MailMessage(_emailsenderconfig.UserName, email, subject, htmlMessage) { IsBodyHtml = true }
);
}
}
}