Tag Archives: Email

C#: How to send emails

Sending a basic email message in a C# application is quite easy thanks to a class called SmptClient. We simply need an address to send to, an address to send from, the message we want to send and the address of an SMTP server, hand it all to the SMTP client, and you’re done:

var from = new MailAddress("me@example.com", "Me");
var to = new MailAddress("you@example.com", "You");

var message = new MailMessage(from, to)
    Subject = "Greetings!",
    Body = "How are you doing today?",

var client = new SmtpClient("smtp.example.com");

using (client)
    catch (SmtpException e)

That was pretty simple, wasn’t it? But what if we need to authenticate with our server? And what if we want to send our message in a more secure manner?

Continue reading C#: How to send emails