My Machine does not send email using Gmail account on VIsual studio 2012

sophiaadaniels

New Member
It's been couple of days, trying to solve that problem.I am using Visual studio 2012. I want to send email using (gmail account) in asp.net C#.There is no problem in the Code it self( I have tried different codes ).but I think it's something related to my machine.Moreover, here are the steps done so far:1- Turning off both ( firewall, Antivirus)2- Running visual Studio as administrator.3- Using Localhost (iis 7 )4- Trying different ports ( 586, 25, 465 ) still I get the error message.here is the exception message (Error):\[code\]System.Net.Mail.SmtpException was unhandled by user code HResult=-2146233088 Message=Failure sending mail. Source=System StackTrace: at System.Net.Mail.SmtpClient.Send(MailMessage message) at _Default.Page_Load(Object sender, EventArgs e) in d:\ThesisIIS\WebSite12\Default.aspx.cs:line 40 at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) InnerException: System.Net.WebException HResult=-2146233079 Message=Unable to connect to the remote server Source=System StackTrace: at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) InnerException: System.Net.Sockets.SocketException HResult=-2147467259 Message=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:c03::6c]:587 Source=System ErrorCode=10060 NativeErrorCode=10060 StackTrace: at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) InnerException: \[/code\]The code:\[code\]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("[email protected]"); myMailMessage.To.Add("[email protected]");// 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("[email protected]", "**YOURPASSWORD**"); smtpServer.EnableSsl = true; smtpServer.Send(MyMailMessage); Response.Redirect("Default.aspx"); }}\[/code\]If anyone can give me an idea I will really appreciate that.
 
Back
Top