You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/projects/Infrastructure/Email/EmailSender.cs

34 lines
1.0 KiB

using MailKit.Net.Smtp;
using MimeKit;
namespace Infrastructure.Email
{
public class EmailSender : IEmailSender
{
public void SendMail(string name,
string from,
string to,
string subject,
string body,
string host,
int port,
string userName,
string password)
{
var message = new MimeMessage();
message.From.Add(new MailboxAddress(name, from));
message.To.Add(MailboxAddress.Parse(to));
message.Subject = subject;
message.Body = new TextPart("html") { Text = body };
using var client = new SmtpClient
{
ServerCertificateValidationCallback = (s, c, h, e) => true
};
client.Connect(host, port, false);
client.AuthenticationMechanisms.Remove("XOAUTH2");
client.Authenticate(userName, password);
client.Send(message);
client.Disconnect(true);
}
}
}