English 中文(简体)
SMTP Service not available
原标题:

I am trying to create a web application which upon entering your email address and message , sends an email with this information from the email address.

I used this:

    try
    {
        NetworkCredential login = new NetworkCredential("your_____@gmail.com", "password");

        System.Net.Mail.MailMessage email = new System.Net.Mail.MailMessage();

        email.To.Add(new MailAddress("my____email@gmail.com"));
        email.From = new MailAddress("your_____@gmail.com");
        email.Subject = "Question";

        email.Body = question;

        SmtpClient client = new SmtpClient("smtp.gmail.com");
        client.EnableSsl = true;
        client.UseDefaultCredentials = false;
        client.Credentials = login;
        client.Send(email);
    }
    catch
    {
    }

But its giving me an SMTP error.

"Service not available, closing transmission channel. The server response was: Cannot connect to SMTP server 209.85.129.111 (209.85.129.111:25), connect error 10051" System.Exception {System.Net.Mail.SmtpException}

最佳回答

To send through your gmail account, you need to connect to port 587:

SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
问题回答

You do not need to specify port 587 - the code works without it. I have successfully sent and received e-mail using:

SmtpClient client = new SmtpClient("smtp.gmail.com");

If you look at the error closely, it says "Cannot connect to SMTP server" and error 10051 means the network is unreachable. Do you have a firewall blocking port 587?

Gmail uses port 465 and the erros show port 25 try using 465 port

http://mail.google.com/support/bin/answer.py?answer=76147





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签