Latest Post

Saturday, 10 September 2016

Simple send Email Code

I am sharing simple send email code

public static Task SendMailAsync(string To, string Subject, string Body)
{
               
    var CredentialUserName = ConfigurationManager.AppSettings["MailUserIdCredential"];
    var Password = ConfigurationManager.AppSettings["MailPasswordCredential"];
    var MailServer = ConfigurationManager.AppSettings["MailServer"];
    var credentialUserName = CredentialUserName;
    var sentFrom = MailSentFrom;
    var pwd = Password;
    SmtpClient client = new SmtpClient(MailServer);
    client.Port = 587;
    client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
    client.UseDefaultCredentials = false;
    // Create the credentials:
   NetworkCredential credentials = new System.Net.NetworkCredential(credentialUserName, pwd);
    client.EnableSsl = true;
    client.Credentials = credentials;
    // Create the message:
    var mail = new MailMessage(sentFrom, To);
    mail.Subject = Subject;
    mail.Body = Body;
    mail.IsBodyHtml = true;
    return client.SendMailAsync(mail);
  }

Government Jobs