[英]error when sending email from asp.net contact page
Iam trying to send an email from my contact page but I keep getting an error 我试图从我的联系页面发送电子邮件,但我不断收到错误消息
I have pasted my code below as well as the error message that is appearing. 我已经在下面粘贴了我的代码以及出现的错误消息。
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'
Dim SendPw As New System.Net.Mail.MailMessage
Dim Smtp As New System.Net.Mail.SmtpClient()
SendPw.To.Add(email.Text)
SendPw.From = New System.Net.Mail.MailAddress("shumbasoft@gmail.com")
SendPw.Subject = "Password for you"
SendPw.Priority = Net.Mail.MailPriority.High
SendPw.Body = "This your new password: "
SendPw.IsBodyHtml = False
Smtp.Host = "smtp.gmail.com"
Smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.PickupDirectoryFromIis
Smtp.Send(SendPw)
End Sub
Have you configure IIS ? 您配置了IIS吗? or make a try with this code, it give good result for me:
或尝试使用此代码,它将为我带来良好的效果:
Dim msgMail As New MailMessage()
Dim myMessage As New MailMessage()
myMessage.From = New MailAddress("sender's email", "sender`s name and surname")
myMessage.[To].Add("recipient's email")
myMessage.Subject = "Subject"
myMessage.IsBodyHtml = True
myMessage.Body = "Message Body"
Dim mySmtpClient As New SmtpClient()
Dim myCredential As New System.Net.NetworkCredential("email", "password")
mySmtpClient.Host = "your smtp host address"
mySmtpClient.UseDefaultCredentials = False
mySmtpClient.Credentials = myCredential
mySmtpClient.ServicePoint.MaxIdleTime = 1
mySmtpClient.Send(myMessage)
myMessage.Dispose()
you need to import Imports system.net.mail
您需要导入
Imports system.net.mail
this did the trick for me!! 这对我有用!! from the localhost to gmail
从本地主机到gmail
Dim Body As String = "From: " + fname.Text + " " + lname.Text + Environment.NewLine + "Email: " + email.Text + Environment.NewLine + Environment.NewLine + "Message" + Environment.NewLine + txtComment.Text
Dim xx As New System.Net.Mail.SmtpClient
xx.EnableSsl = True
xx.Host = "smtp.gmail.com"
Dim cred As New System.Net.NetworkCredential("example@gmail.com", "examplepassword")
xx.Credentials = cred
xx.Send(email.Text, "sendexample@gmail.com ", subject.Text, Body)
ClearFields()
lblEmail.ForeColor = Drawing.Color.Green
lblEmail.Text = "message sent"
lblEmail.Visible = True
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.