Smtp with c# through gmail.  
Author Message
Lucas2





PostPosted: .NET Framework Networking and Communication, Smtp with c# through gmail. Top

Hi guys,

hope you can help. I have installed Visual Web Developed and started learning ASP.NET with c#.

I am currently trying to build a website that sends email through gmail's smtp, here's the code:
_______________________________________________________________________
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
using System.Net;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();




mail.Subject = "subject";


mail.IsBodyHtml = true;
mail.Body = "message";

System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = true;
smtp.Credentials = cred;
smtp.Port = 587;
smtp.Send(mail);
}
}

_______________________________________________________________________

And I am getting this error message:

Server Error in '/email' Application.
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

I am testing the app on the server that's integrated in Visual Web Developer, could that be the problem What else could it be

Please help.


.NET Development9  
 
 
frederikm





PostPosted: .NET Framework Networking and Communication, Smtp with c# through gmail. Top

Hi

the fact that you are testing in web dev should not have any impact.

the error you get looks like a timeout, so either your request never made it there, or it took too long.

do you have a firewall running if so, turn it off and try again.

Otherwise wrap your code in a try catch and see if there is any innerexception that gives you more detail..

Hope this helps, please close the thread if it does



 
 
ahmedilyas





PostPosted: .NET Framework Networking and Communication, Smtp with c# through gmail. Top

indeed, its a good point picked up about the firewall - some firewalls block sending data from applications, be it a web app running from your box or a winform app - check the firewall, as suggested previously - the same applies for anti virus software too. In addition, be sure that the configuration settings are correctly configured for the gmail account