Last active
March 14, 2024 06:33
-
-
Save overwatcheddude/3542e91ba1c9ad8cde46d22f5203f1c5 to your computer and use it in GitHub Desktop.
Sending an email in C#
This file contains hidden or 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
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", "[email protected]")); | |
message.To.Add(new MailboxAddress("Mrs. Chanandler Bong", "[email protected]")); | |
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