I was trying to send email using gmail account on asp.net c#, but I keep getting this error:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond [2607:f8b0:400c:c01::6c]:587
I have tried different codes from different resources,but none of them worked with my project More over I've tried those steps but still not working:
- trying ports 25, 465, 587 on both VS 2012 server and localhost (iis 7).
- Firewall set to off , antivirus set to off.
- starting visual studio as administrator.
Please , can anyone tell me what is the reason behind this error. and if there is possibility to change something , where should I start..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default6 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var myMailMessage = new System.Net.Mail.MailMessage();
        myMailMessage.From = new System.Net.Mail.MailAddress("serveremail@gmail.com");
        myMailMessage.To.Add("youremail@yahoo.com");// Mail would be sent to this address
        myMailMessage.Subject = "Feedback Form";
        myMailMessage.Body = "Hello";
        var smtpServer = new System.Net.Mail.SmtpClient("smtp.gmail.com");
        smtpServer.Port =587;
        smtpServer.Credentials = new System.Net.NetworkCredential("serveremail@gmail.com", "**YOURPASSWORD**");
        smtpServer.EnableSsl = true;
        smtpServer.Send(MyMailMessage);
        Response.Redirect("Default.aspx");
    }
}
 
     
     
    