Created
January 17, 2020 22:39
-
-
Save ljchuello/9a023264d6864dc7dda659193b739672 to your computer and use it in GitHub Desktop.
Send email with SMTP 465 in C# (MailKit)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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