2014-04-29 70 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

相關問題