Thursday, 21 February 2013

Send Mail from gmail server

Reuiqred Name space " using System.Net.Mail; "
////  (1) Create the MailMessage instance

                MailMessage mm = new MailMessage();

  ////'(2) Assign the MailMessage's properties

                mm.From = new MailAddress("", "Ravi");


                mm.Subject = "Any Subject  ";

                mm.Body = ex.Message.ToString(); //Body of your mail

                mm.IsBodyHtml = false;//

 ////'(3) Create the SmtpClient object

                SmtpClient smtp = new SmtpClient("",587);

                smtp.EnableSsl = true;

                //smtp.DeliveryMethod = SmtpDeliveryMethod.Network; //it may be depend on your network

 //'(4) Send the MailMessage (will use the Web.config settings)

                smtp.Credentials = new System.Net.NetworkCredential("GmailId", "Passward");            

No comments:

Post a Comment