我创建将电子邮件发送到电子邮件帐户的一种形式,用下面的code。
I have created a form to send email to an email account and used the following code.
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 EX preSS运行我的项目。我知道,IIS EX preSS犯规支持SMTP,如果我是正确的。但是,如果code是正确的,应该正常运行。反正我发表我的网站通过.NET发布工具,我的GoDaddy的帐户。当我尝试从形式发送邮件我收到以下错误消息。
I am using IIS express to run my project. I know that IIS express doesnt support smtp, if I am correct. But if the code is correct it should run properly. Anyway I published my site through .net publish tool to my godaddy account. when I try to send email from the form I am getting the following error message.
邮箱无法使用。服务器响应为:5.7.1无法中继info@test.com
Mailbox unavailable. The server response was: 5.7.1 Unable to relay for "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"
我尝试了上面的code,仍然它不工作。我只是无法弄清楚我在做什么wroong这里。我记得我曾经得到这个工作的某个时候回来。但我不记得如何。
I tried the above code and still its not working. I just cant figure out what I am doing wroong here. I remember I used got this working sometime back. But I cant remember how.
您丢失SMTPSERVER凭证
Your missing SmtpServer Credentials
client.Credentials = New Net.NetworkCredential("username@gmail.com", "password")
如果不是这则请设置您的SMTP虚拟服务器,如图例如在http://$c$cbetter.com/petervanooijen/2006/04/05/using-localhost-as-mailserver-5-7-1-unable-to-relay-for-xxx/
If not this then please configure your smtp virtual server as shown in example http://codebetter.com/petervanooijen/2006/04/05/using-localhost-as-mailserver-5-7-1-unable-to-relay-for-xxx/