[英]Sending Mail Failure: SMTP Exception
我寫信是希望你能幫助我。 今天,我將使用vb.net開發一個郵件應用程序,為此,我編寫了下面給出的代碼。
此代碼引發異常(“ SMTP異常”)
Public Function SendAnEmail(ByVal MsgBody As String)
Try
Dim MsgFrom As String = "amolkadam.a@gmail.com"
Dim MsgTo As String = "amolkadam.a@gmail.com"
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
您已經編寫了將自己的PC用作郵件服務器的代碼,對嗎? 這樣您就不會誤解發送到SmtpClient
的IP應該是服務器的IP。
如果確實在本地PC上運行SMTP服務器,是否嘗試過可以通過其他客戶端從該服務器發送電子郵件? 並且該服務器將接受帶有的電子郵件,其中包含from
gmail.com的地址(某些服務器則不會)。 您可以按照此處的說明使用任何telnet客戶端進行嘗試,只需根據需要交換地址即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.