Saturday, January 8, 2011

Send Email from asp.net


using System.Net.Mail;



        String userName = "your username";
        String passWord = "your password";
        String sendr = "your email id";
        String recer = "receiver of email";
        String subject = "subject of email";
        String body = "body part of email";

        MailMessage msgMail = new MailMessage(sendr, recer, subject, body);

        int PortNumber = 587; // port number
        SmtpClient smtp = new SmtpClient("smtpservername", PortNumber);
        msgMail.IsBodyHtml = true;
// if your body contains html tag

        
smtp.EnableSsl = true;
        smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
        smtp.Credentials = new System.Net.NetworkCredential(userName, passWord);
        try
        {

            smtp.Send(msgMail);
        }
        catch (Exception exp)

        {
            // error handling
        }

No comments:

Post a Comment