我试图从我的联系页面发送电子邮件,但我一直收到错误
我已粘贴下面的代码以及出现的错误消息。
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
答案 0 :(得分:0)
您是否配置了IIS?或尝试使用此代码,它为我提供了良好的结果:
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()
您需要导入Imports system.net.mail
答案 1 :(得分:0)
这对我来说很有用!!从localhost到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