I have written a VB.NET code that should sent email via my server. My server uses SSL which is self signed (I think) (R3/Let's Encrypt). The following code gives error "The remote certificate is invalid according to the validation procedure.". If I turn off SSL then I get error "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first". How to solve it ?
Dim MyMailMessage As New MailMessage()
MyMailMessage.From = New MailAddress("[email protected]", "My Site")
MyMailMessage.Subject = "Test"
MyMailMessage.Body = "<BR><B>This is a test email</B><BR><BR>Bye"
MyMailMessage.IsBodyHtml = True
Dim SMTP As New SmtpClient("mail.mysite.com")
SMTP.Port = 587
SMTP.EnableSsl = True
SMTP.Credentials = New System.Net.NetworkCredential("[email protected]", "password_here")
' add to address
MyMailMessage.To.Add("[email protected]")
' Send Email
SMTP.Send(MyMailMessage)
MyMailMessage.To.Clear()