Skip to content

C#

Sending transactional emails from your C# applications using System.Net.Mail provides a reliable and straightforward solution for email delivery. This built-in .NET framework capability eliminates the need for third-party dependencies while offering robust functionality for composing and dispatching personalized messages.

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("[email protected]", "Recipient");
MailAddress from = new MailAddress("[email protected]", "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