Skip to content

Instantly share code, notes, and snippets.

@ljchuello
Created January 17, 2020 22:39
Show Gist options
  • Save ljchuello/9a023264d6864dc7dda659193b739672 to your computer and use it in GitHub Desktop.
Save ljchuello/9a023264d6864dc7dda659193b739672 to your computer and use it in GitHub Desktop.
Send email with SMTP 465 in C# (MailKit)
// Leonardo Chuello - ljchuello@gmail.com
using MailKit.Net.Smtp;
using MailKit.Security;
using MimeKit;
namespace Test
{
public class Email
{
public void Send()
{
MimeMessage mimeMessage = new MimeMessage();
mimeMessage.To.Add(new MailboxAddress("anywere@gmail.com"));
mimeMessage.From.Add(new MailboxAddress("Leonardo Chuello", "ljchuellom@entecprois.com"));
mimeMessage.Subject = "Subject";
mimeMessage.Body = new BodyBuilder { HtmlBody = "This mail send with MimeKit 😎" }.ToMessageBody();
using (SmtpClient smtpClient = new SmtpClient())
{
smtpClient.ServerCertificateValidationCallback = (l, j, c, m) => true;
smtpClient.Connect("mail.entecprois.com", 465, SecureSocketOptions.SslOnConnect);
smtpClient.Authenticate("ljchuellom@entecprois.com", "xxxxxx");
smtpClient.Send(mimeMessage);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment