2012-01-28 72 views
2

当我尝试与使用Gmail VB.Net或C#我不断收到以下消息发送电子邮件:不发送电子邮件 - 试图访问一个插座以其访问权限禁止的方式 - 无法访问远程服务器。 我一直在使用Gmail的几个帐户尝试包括在过去的工作VB.Net代码,如下所示:与Gmail和C#发送电子邮件/ VB.Net不再起作用

Message = New MailMessage(Sender, Recipient, Subject, MessageBody) 

SMTPServer = New SmtpClient("smtp.gmail.com", 587)'Port 465 fails as well 
SMTPServer.EnableSsl = True 

SMTPServer.Credentials = New NetworkCredential("[email protected]", "password") 
SMTPServer.Send(Message) 

(据我所知,在web.config可用于很多以上)。

显然Gmail中必须更改了某些设置或类似的东西?

+1

关闭防火墙并重试。 – Jashwant 2012-01-28 10:56:24

+0

我试图关闭防火墙,但没有任何区别。 – Lee 2012-01-28 11:05:35

回答

4

这是McAfee防病毒软件防止电子邮件的发送。感谢所有的帮助,并且很抱歉浪费大家的时间。

+0

;)我的第一个评论你的问题 – Jashwant 2012-01-30 11:16:08

1

我不知道如何评论这样:我想你忘记了港口和几件事情。看看这有助于:

Imports System.Net.Mail 

Protected Sub btnSendEmail_Click(ByVal sender As Object, ByVal e As EventArgs) 
    Dim mail As MailMessage = New MailMessage() 
    mail.To.Add("[email protected]") 
    mail.From = New MailAddress("[email protected]") 
    mail.Subject = "Email using Gmail" 

    String Body = "Sending mail using Gmail's SMTP" 
    mail.Body = Body 

    mail.IsBodyHtml = True 
    Dim smtp As SmtpClient = New SmtpClient() 
    smtp.Host = "smtp.gmail.com" 
    smtp.Credentials = New System.Net.NetworkCredential 
     ("[email protected]","password") 
    smtp.EnableSsl = True 
    smtp.Port = 587 
    smtp.EnableSsl = true 
    smtp.Send(mail) 
End Sub 

试试这个编辑

+0

我试过你的代码,并得到和以前完全相同的异常,以及'无法连接到远程服务器'。上次我发送Gmail邮件时,我使用的是Vista Home Premium x32,现在我正在使用Windows 7 Ultimate x64,除此之外,我无法想象任何不同之处。 – Lee 2012-01-28 11:01:20

+0

最新错误?因为当我尝试它时它工作正常。 – 2012-01-28 11:03:28

+0

尝试这可能工作 – 2012-01-28 11:10:04

3

此代码工作正常,我:

try 
    { 
     MailMessage mail = new MailMessage();  //using System.Net.Mail namespace 
     mail.To.Add("[email protected]");    //Enter reciever's email address 
     mail.From = new MailAddress("[email protected]"); //Enter sender's email address 
     mail.Subject = "Testing mail..."; 
     mail.Body = @"Lets-code ! Lets-code to make it simpler"; 
     mail.IsBodyHtml = true;     //Body of mail supports html tags 
     SmtpClient smtp = new SmtpClient(); 
     smtp.Host = "smtp.gmail.com"; 
     smtp.Port = 587; 
     smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "pwd"); 
     // Your gmail username and password 
     smtp.EnableSsl = true;   //Gmail uses a encrypted connection 
     smtp.Send(mail); 
     Response.Write("Mail Sent Successfully"); 
    } 

catch(Exception ex) 
    { 
     Response.Write(ex.Message); 
    } 

如果这没有帮助,尝试另一台机器上。 Windows 7拥有自己的防火墙。也检查出来。

+0

我停用防火墙后,我想你的代码以及仍然得到相同的错误消息,这似乎是一个机器特定的问题:( – Lee 2012-01-28 11:23:02

0

谷歌有保护您的Gmail帐户的新程序,使用此代码,您必须转到Gmail设置并关闭安全性较低的客户的阻塞。