【问题标题】:Unable to send email from asp.net form无法从 asp.net 表单发送电子邮件
【发布时间】:2012-07-01 20:21:32
【问题描述】:

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

       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"

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

【问题讨论】:

  • 您似乎需要配置您的邮件服务器。
  • 我相信你已经将你的虚拟 Smtp 服务器配置为在本地主机上工作,你也可以尝试使用 SmtpMail.UseDefaultCredentials = True before Send(msg)

标签: asp.net .net vb.net


【解决方案1】:

您缺少的 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-for-xxx/ 所示

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2019-01-23
  • 1970-01-01
  • 1970-01-01
  • 2011-11-17
  • 2019-02-17
  • 2012-03-15
  • 2021-04-22
相关资源
最近更新 更多