Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Mailkit, Email Send.
public static async Task SendMail()
//From Address
string FromAddress = "";
string FromAdressTitle = "Email from ASP.NET Core 1.1";
//To Address
string ToAddress = "";
string ToAdressTitle = "Microsoft ASP.NET Core";
string Subject = "Hello World - Sending email using ASP.NET Core 1.1";
string BodyContent = "ASP.NET Core was previously called ASP.NET 5. It was renamed in January 2016. It supports cross-platform frameworks ( Windows, Linux, Mac ) for building modern cloud-based internet-connected applications like IOT, web apps, and mobile back-end.";
//Smtp Server
string SmtpServer = "localhost";
//Smtp Port Number
int SmtpPortNumber = 25;
var mimeMessage = new MimeMessage();
mimeMessage.From.Add(new MailboxAddress(FromAdressTitle, FromAddress));
mimeMessage.To.Add(new MailboxAddress(ToAdressTitle, ToAddress));
mimeMessage.Subject = Subject;
mimeMessage.Body = new TextPart("plain")
Text = BodyContent
using (var client = new SmtpClient())
client.Connect(SmtpServer, SmtpPortNumber, false);
// Note: only needed if the SMTP server requires authentication
// Error 5.5.1 Authentication
// client.Authenticate("From Address Email", "Password");
await client.SendAsync(mimeMessage);
Console.WriteLine("The mail has been sent successfully !!");
catch (Exception ex)
throw ex;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment