Skip to content

C#

Emails can be sent from C# applications using the .NET framework's native System.Net.Mail capability.

Program.cs
using System.Net;
using System.Net.Mail; 

var smtpClient = new SmtpClient("in.smtp.sendamatic.net")
{
    Port = 587,
    Credentials = new NetworkCredential("[mail credential user]", "[mail credential password]"),
    EnableSsl = true,
};


MailAddress to = new MailAddress("recipient@example.com", "Recipient");
MailAddress from = new MailAddress("sender@yourdomain.com", "Sender");

MailMessage email = new MailMessage(from, to);
email.Subject = "Hello world";
email.Body = "This is a test";

try
{
    smtpClient.Send(email);
}
catch (SmtpException ex)
{
    Console.WriteLine(ex.ToString());
}

Further reading