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 ? 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
this did the trick for me!! from the localhost to 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.