Skip to content

Instantly share code, notes, and snippets.

@overwatcheddude
Last active March 14, 2024 06:33
Show Gist options
  • Save overwatcheddude/3542e91ba1c9ad8cde46d22f5203f1c5 to your computer and use it in GitHub Desktop.
Save overwatcheddude/3542e91ba1c9ad8cde46d22f5203f1c5 to your computer and use it in GitHub Desktop.
Sending an email in C#
using MimeKit;
using MailKit.Net.Smtp;
namespace TestClient
{
class Program
{
public static void Main(string[] args)
{
var message = new MimeMessage();
message.From.Add(new MailboxAddress("Joey Tribbiani", "joey@friends.com"));
message.To.Add(new MailboxAddress("Mrs. Chanandler Bong", "chandler@friends.com"));
message.Subject = "How you doin'?";
message.Body = new TextPart("plain")
{
Text = @"Hey Chandler,
I just wanted to let you know that Monica and I were going to go play some paintball, you in?
-- Joey"
};
using var client = new SmtpClient();
client.Connect("localhost", 25, false);
// Note: only needed if the SMTP server requires authentication
// client.Authenticate("username", "password");
client.Send(message);
client.Disconnect(true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment