// C# code
using (SmtpClient smtpClient = new SmtpClient(SmtpDomain, SmtpPortNumber))
{
smtpClient.DeliveryMethod = SmtpDeliveryMethod;
smtpClient.UseDefaultCredentials = UseDefaultCredentials;
smtpClient.EnableSsl = true;
smtpClient.Credentials = new NetworkCredential(SmtpUsername, appsPasswrod);
MailMessage mailMessage = new MailMessage { /* ... */ };
smtpClient.Send(mailMessage);
}