Sending email via Outlook365 from VB6/VB.net 4.0 application

222 views Asked by At

We currently have a legacy VB6/VB.Net 4.0 application (we're stuck with those because of a need to support XP unfortunately), and one of its functions is to send out email. It currently works with various of our clients SMTP servers just fine using the Ostrosoft SMTP component. However is doesn't work with Office365 as that now requires the use of TLS1.2 with 'StartTLS', which the Ostrosoft component doesn't support.

I've tried various things in .Net, but nothing seems to work.

e.g.:

        Try
            Using SMTPMailServer As New Net.Mail.SmtpClient()
                Using MailMessage As Net.Mail.MailMessage = New Net.Mail.MailMessage()
                    SMTPMailServer.Port = 587
                    SMTPMailServer.Host = "smtp.office365.com"
                    SMTPMailServer.EnableSsl = True
                    SMTPMailServer.DeliveryMethod = SmtpDeliveryMethod.Network
                    SMTPMailServer.UseDefaultCredentials = False
                    SMTPMailServer.Credentials = New Net.NetworkCredential("**id**", "**password**")

                    MailMessage.From = New MailAddress(FromAddress)
                    MailMessage.To.Add(ToAddress)

                    MailMessage.Subject = $"Test Email {DateTime.Now}"
                    MailMessage.Body = "This is for testing SMTP mail using Method 1"

                    SMTPMailServer.Send(MailMessage)
                End Using

                MsgBox("Mail sent")
            End Using
        Catch ex As Exception
            MsgBox($"Error : {ex.Message}")
        End Try

This results in the following error:

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 Client not authenticated to send mail. Error: 535 5.7.139 Authentication unsuccessful, the request did not meet the criteria to be authenticated successfully.

Does anyone have a solution to this? Thanks.

Note, I've tried setting the ServicePointManager.SecurityProtocol to 3072, no change.

0

There are 0 answers