1

我创建了一个表单来向电子邮件帐户发送电子邮件并使用以下代码。

       Dim client As New SmtpClient()
        Dim emailmessage As New MailMessage()

        Dim emailfrom As New MailAddress(txtEmail.Text)

        emailmessage.Subject = "Web Submission"
        emailmessage.Body = "Web submission received from " & txtName.Text & ". Phone no: "     & txtPhone.Text & "."
        client.Host = "localhost"
        client.Port = 25
        emailmessage.From = emailfrom
        emailmessage.To.Add("info@test.com")

        client.Send(emailmessage)
        lblMessage.Text = "Thank you, we will contact you soon"

我正在使用 IIS express 来运行我的项目。如果我是正确的,我知道 IIS express 不支持 smtp。但如果代码正确,它应该可以正常运行。无论如何,我通过 .net 发布工具将我的网站发布到我的 godaddy 帐户。当我尝试从表单发送电子邮件时,我收到以下错误消息。

信箱不可用。服务器响应为:5.7.1 无法中继“info@test.com”

Dim msg As New MailMessage()
        msg.To = "test@gmail.com"
        msg.From = "test@gmail.com"
        msg.Subject = "test"
        'msg.BodyFormat = MailFormat.Html
        msg.BodyFormat = MailFormat.Text
        msg.Body = "hi"

        SmtpMail.SmtpServer = "localhost"

        SmtpMail.Send(msg)
        lblMessage.Text = "An Email has been send to " & "test@gmail.com"

我尝试了上面的代码,但仍然无法正常工作。我只是想不通我在这里做错了什么。我记得我曾经在某个时候得到过这个工作。但我不记得怎么了。

4

1 回答 1

2

您缺少的 SmtpServer 凭据

        client.Credentials = New Net.NetworkCredential("username@gmail.com", "password")

如果不是这样,请配置您的 smtp 虚拟服务器,如示例http://codebetter.com/petervanooijen/2006/04/05/using-localhost-as-mailserver-5-7-1-unable-to-relay-为-xxx/

于 2012-07-01T20:39:22.593 回答