2010-08-04 194 views
0

我在寫信,希望你能幫助我。今天我要開發一個使用vb.net的郵件應用程序,爲此我編寫了下面給出的代碼。發送郵件失敗:SMTP異常

此代碼拋出異常(「SMTP異常」)

Public Function SendAnEmail(ByVal MsgBody As String) 
    Try 
     Dim MsgFrom As String = "[email protected]" 
     Dim MsgTo As String = "[email protected]" 
     Dim MsgSubject As String = "claim Report" 

     ' Pass in the message information to a new MailMessage 

     Dim msg As New Net.Mail.MailMessage(MsgFrom, MsgTo, MsgSubject, MsgBody) 

     ' Create an SmtpClient to send the e-mail 
     Dim mailClient As New SmtpClient("219.64.91.90") ' = local machine IP Address 

     ' Use the Windows credentials of the current User 
     mailClient.UseDefaultCredentials = True 

     ' Pass the message to the mail server 
     mailClient.Send(msg) 

     ' Optional user reassurance: 
     MessageBox.Show(String.Format("Message Subject ' {0} ' successfully sent From {1} To {2}", MsgSubject, MsgFrom, MsgTo), "EMail", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Information) 

     ' Housekeeping 
     msg.Dispose() 

    Catch ex As FormatException 
     MessageBox.Show(ex.Message & " :Format Exception") 
    Catch ex As SmtpException 
     MessageBox.Show(ex.Message & " :SMTP Exception") 
    End Try 
End Function 
+0

您能否顯示異常請-e.g. 550我們不會中繼等 – StuartLC 2010-08-04 04:47:50

+0

發送郵件失敗:SMTP異常 – 2010-08-04 05:12:01

回答

0

你寫使用自己的PC作爲郵件服務器的代碼,是正確的?只是所以你沒有誤解,發送到SmtpClient的IP應該是服務器的IP。

如果你有一個SMTP服務器在本地PC上運行,你有沒有嘗試過,你可以從該服務器通過其他客戶端發送電子郵件?並且服務器將接受包含gmail.com地址的from電子郵件(有些服務器不會)。 您可以按照說明here使用任何telnet客戶端來嘗試此操作,只需根據需要交換地址即可。