This code snippet shows how to send an email with network credentials.
SmtpClient Smtp = new SmtpClient();
MailMessage Message = new MailMessage();
try
{
Smtp.Host = "";
Smtp.Port = "";
string SmtpUsername = "";
string SmtpPassword = "";
string MailFrom = "";
string MailFromName = "";
Smtp.Credentials = new NetworkCredential(SmtpUsername, SmtpPassword);
MailAddress FromAddress = new MailAddress(MailFrom, MailFromName);
Message.From = FromAddress;
Message.To.Add(MailFrom);
Message.Subject = "Subject";
Message.IsBodyHtml = true;
Message.Body = "Sample message";
Smtp.Send(Message);
}
catch (SmtpException SmtpEx)
{
// Error
}
No comments:
Post a Comment