junaid sarfraz

junaid sarfraz

  • NA
  • 16
  • 31.3k

email using smtp.gmail.com

Feb 17 2011 7:00 AM
when i use to send mail using gmail error occur enable to  connect to remote server??

help me how to sove this error



private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

                mail.From = new MailAddress("[email protected]");
                mail.To.Add("[email protected]");
                mail.Subject = "Test Mail";
                mail.Body = "This is for testing SMTP mail from GMAIL";


                SmtpServer.Port = 587;
                   
                SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
                SmtpServer.EnableSsl = true;

                SmtpServer.Send(mail);
                MessageBox.Show("mail Send");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

Answers (14)