Saturday, 28 September 2013

How to configure mail Settings in asp.net through SMTP

public void sendmail()
    {
        MailMessage msg = new MailMessage();
//From Address
        msg.From = new MailAddress(“abc@abc.com”);
//To Address
        msg.To.Add(“xyz@xyz.com”);
// Your  message Subject
        msg.Subject = “Your Message Subject”;
//Your message Body
        msg.Body = “Your Message Body”;

        msg.IsBodyHtml = true;
        SmtpClient smtpClient = new SmtpClient();
//Please write your DNS name instead of abc.com

        smtpClient.Host = “smtp.abc.com”;
//either you select port 25 or 587 as per your requirement
       smtpClient.Port = 25;
        smtpClient.EnableSsl = false;
        smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;

        smtpClient.Credentials = new NetworkCredential(msg.From.ToString(), “your password”);
// For Maximum timeout
        smtpClient.Timeout = 20000;
        smtpClient.Send(msg);
    }

No comments:

Post a Comment