我创建了一个表单来向电子邮件帐户发送电子邮件并使用以下代码。
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"
我尝试了上面的代码,但仍然无法正常工作。我只是想不通我在这里做错了什么。我记得我曾经在某个时候得到过这个工作。但我不记得怎么了。