Using MailKit to send emails via GoDaddy SMTP on ASP.Net Core app
I have an application that needs to send emails, application is coded in c# asp.net core and most of the previous packges I used int he past not compatible with asp.net core. I came across with MailKit seem to be pretty popular for email sending in c#, thought give it a go.
install the NuGet
https://github.com/jstedfast/MailKit
After few tries, I was able to find the optimum settings to work with GoDaddy SMTP server. Below is the code snippet.
using System;
using MailKit.Net.Smtp;
using MailKit;
using MimeKit;
var message = new MimeMessage();
message.From.Add(new MailboxAddress("Joey Tribbiani", "me@my-domain.com.au"));
message.To.Add(new MailboxAddress("Mrs. Chanandler Bong", "one.asanka@gmail.com"));
message.Subject = "testing with GoDaddy SMTP";
message.Body = new TextPart("plain")
{
Text = @"Hey Asanka, this is working ? -- Asanka"
};
using (var client = new SmtpClient())
{
client.ServerCertificateValidationCallback = (s, c, h, e) => true;
client.Connect("xxxxxxxxxxxx.prod.xxxx.secureserver.net", 465, true);
client.AuthenticationMechanisms.Remove("XOAUTH2");
client.Authenticate("me@my-domain.com.au", "super-secret-password");
client.Send(message);
client.Disconnect(true);
}
