2014-04-29 72 views
1

即时发送电子邮件时遇到错误。这里是错误失败发送电子邮件无法连接远程服务器

Error Email Sending Failure

什么是此异常的实际错误,因为我在这个新手中,这里的方式是我的代码行:

Try 
       Dim SmtpServer As New SmtpClient() 
       Dim mail As New MailMessage() 

       SmtpServer.Credentials = New _ 
       Net.NetworkCredential("[email protected]", "passwordexample") 
       SmtpServer.EnableSsl = True 
       SmtpServer.Port = 587 
       SmtpServer.Host = "smtp.gmail.com" 

       mail = New MailMessage() 
       mail.From = New MailAddress("[email protected]") 
       mail.To.Add("[email protected]") 
       mail.Subject = "Change Request Submitted" 
       mail.Body = "Dear User, " & Environment.NewLine & Environment.NewLine & Environment.NewLine & Environment.NewLine & "One Notification have been submitted," & Environment.NewLine & "Please check the change request on the intranet application" 

//ad this line the error SmtpServer.Send(mail) 
       SmtpServer.EnableSsl = True 
       MsgBox("Notification emailed successfully") 
      Catch ex As Exception 
       MsgBox(ex.ToString) 
      End Try 
+0

做你的互联网服务提供商允许您发送的邮件? SMTP通常被阻止。 – jgauffin

+0

@jgauffin她似乎在使用GMail。它可以是两步验证,也可以不通过她的帐户启用POP或IMAP。 – Codexer

回答

1

请看这个回答...

Sending Email from Visual Basic

如果仍然无法发送电子邮件....

是否启用POP或IMAP在Gmail中? 登录Gmail网页界面。打开“设置”页面上的“转发和POP/IMAP”标签,并配置IMAP或POP。在Gmail中启用此功能后,请确保您点击“保存更改”,以便Gmail可以与您的邮件客户端进行通信。

如果你有2个步骤验证..

获取一个应用程序专用密码 谷歌会自动生成,你将只需要一次,当你设置了谷歌邮件您的移动设备或电子邮件软件上设置密码。您可以轻松地为要使用的每个设备或电子邮件软件生成密码。

步骤1: 在2步验证屏幕的底部,在应用程序专用密码旁边,单击管理应用程序专用密码。授权访问您的Google帐户屏幕将打开。

步骤2: 在授权访问您的Google帐户屏幕上,在名称字段中,输入名称以帮助您记住用于访问您的帐户的应用程序,然后单击生成密码。然后,您将看到一个密码,您将使用该密码来配置您的移动设备或电子邮件软件。保持此屏幕打开,直到您准备好输入密码(请参阅下面的第4部分)。使用设备名称创建密码将显示在底部。完成使用密码后,单击完成。

第3步: 要为其他设备或电子邮件软件设置密码,只需在名称字段中输入密码的名称,然后单击生成密码即可。您将收到另一个密码。

参见更多...

http://www.oit.umass.edu/support/google-apps/configure-google-mail-email-software-mobile-devices

-2
Dim SmtpServer As New SmtpClient() 
    SmtpServer.Credentials = New Net.NetworkCredential("EMAIL [email protected]", "YOUR PASSWORD") 
    SmtpServer.Port = 25 
    SmtpServer.Host = "smtp.gmail.com" 
    SmtpServer.EnableSsl = True 
    Dim omail As New MailMessage() 


    omail.From = New MailAddress("FROM EMAIL @gmail.com", "Message", System.Text.Encoding.UTF8) 

    omail.Subject = "test subject" 
    omail.To.Add("[email protected]") 

    SmtpServer.SendAsync(omail, Nothing) 

Catch ex As Exception 
    MsgBox(ex.ToString) 
End Try 

如果没't work try SmtpServer.Port = 587

+0

解释你自己 – jgauffin

+1

'587'可能会被防火墙阻止@jgauffin – Bender

+2

任何人都可以从你的示例代码中读到这个吗?总是解释你的答案与原始代码相比所做的更改。否则,你没有帮助。 – jgauffin

相关问题