0

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("support@mysite.com", "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("support@mysite.com", "password_here")

    ' add to address
    MyMailMessage.To.Add("abc@gmail.com")
    ' Send Email
    SMTP.Send(MyMailMessage)

    MyMailMessage.To.Clear()
Greatchap
  • 382
  • 8
  • 21
  • I hope this help you : https://stackoverflow.com/questions/777607/the-remote-certificate-is-invalid-according-to-the-validation-procedure-using – Keyvan Soleimani Jan 04 '22 at 07:44
  • I have seen the above link but it's solutions did not work for me – Greatchap Jan 04 '22 at 07:55
  • If it's a Let's Encrypt certificate, it's not self-signed. Have you inspected the certificate and made sure it's issued to the right host name (**mail**.mysite.com in your example) and not perhaps for e.g. **www**.mysite.com? If it's not a [wildcard certificate](https://en.wikipedia.org/wiki/Wildcard_certificate) and it's issued for the latter (or any other host), it is indeed invalid for **mail**.mysite.com – Hel O'Ween Jan 04 '22 at 15:59
  • I checked and its indeed issued to mail.mysite.com – Greatchap Jan 05 '22 at 03:59

0 Answers0