Best Industrial Training in C,C++,PHP,Dot Net,Java in Jalandhar

Monday, 6 February 2012

How to send email using Gmail Server?

Add Following namespaces:
using System.Net.Mail;
using System.Net.Mime;

Add this code in button_click

 MailMessage mail = new MailMessage();
 SmtpClient SmtpServer = new SmtpClient();
        SmtpServer.Credentials = new System.Net.NetworkCredential
                    ("inder@gmail.com", "gmailpassword");
        SmtpServer.Port = 587;
        SmtpServer.Host = "smtp.gmail.com";
        SmtpServer.EnableSsl = true;
        mail = new MailMessage();
        String[] addr = TextBox1.Text.Split(',');
      
            mail.From = new MailAddress("abs@gmail.com");
           
                mail.To.Add(TextBox1.Text);
            mail.Subject = "Forget Password";
            mail.Body = "ur password is:::::"+pwd;
            //if (ListBox1.Items.Count != 0)
            //{
            //    for (i = 0; i < ListBox1.Items.Count; i++)
            //        mail.Attachments.Add(new Attachment(ListBox1.Items[i].ToString()));
            //}
            //mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
            //mail.ReplyTo = new MailAddress(TextBox1.Text);
            SmtpServer.Send(mail);   


Finally You can send email using gmail server...........

Hope its useful for all of you.











1 comment: