I have to following code:
Try
Dim mail As New MailMessage()
Dim SmtpServer As New SmtpClient("smtp.gmail.com")
mail.From = New MailAddress(txtid.Text)
mail.[To].Add(TextBox1.Text)
mail.Subject = txtsub.Text
mail.Body = txtmess.Text
' mail.Attachments.Add(New Attachment(OpenFileDialog1.FileName))
SmtpServer.Port = 587
SmtpServer.Credentials = New System.Net.NetworkCredential(txtid.Text, txtpass.Text)
SmtpServer.EnableSsl = True
SmtpServer.Send(mail)
MsgBox("E-mail Has Been Send Successfully !")
Catch ex As Exception
MsgBox(ex.Message)
End Try
on the step
SmtpServer.Send(mail)
I'm always getting an error : Failure sending mail
Any idea how to fix it?
Note that I'm using VB.NET
Try configuring your SMTP server on port 465 (with SSL) and port 587 (with TLS), works for me.