简体   繁体   English

发送邮件失败:SMTP异常

[英]Sending Mail Failure: SMTP Exception

I'm writing in the hope that you will help me. 我写信是希望你能帮助我。 Today I'm going to develop a mail application using vb.net, for this I wrote the code given below. 今天,我将使用vb.net开发一个邮件应用程序,为此,我编写了下面给出的代码。

This code throws the exception ("SMTP Exception") 此代码引发异常(“ 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

You've written the code to use your own PC as the mail server, is that correct? 您已经编写了将自己的PC用作邮件服务器的代码,对吗? Just so you haven't misunderstood that the IP sent in to SmtpClient should be the IP of the server. 这样您就不会误解发送到SmtpClient的IP应该是服务器的IP。

If you do have an SMTP server running on your local PC, have you tried that you can send emails from that server via some other client? 如果确实在本地PC上运行SMTP服务器,是否尝试过可以通过其他客户端从该服务器发送电子邮件? And that the server will accept emails with a from containing a gmail.com address (some servers won't). 并且该服务器将接受带有的电子邮件,其中包含from gmail.com的地址(某些服务器则不会)。 You can try this using any telnet client by following the instructions here , just exchanging the addresses as needed. 您可以按照此处的说明使用任何telnet客户端进行尝试,只需根据需要交换地址即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM