[英]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.