Home > Blockchain >  VB SMTP through System.Net.Mail stopped working
VB SMTP through System.Net.Mail stopped working

Time:07-15

I have a VB.NET application that sends emails to users letting them know something requires their attention.

The mail is generated within the app and sent through a Microsoft 365 Account.

This has worked for years without an issue, however 2 days ago it suddenly stopped working.

I have tested the mail account outside of the app and it works fine.

When I log in to the 365 account there are no items in the outbox or sent items for the last 2 days and no failed email notices in the inbox. Therefore I have concluded the issue must be somehow in the app.

The problem with this is that I have not changed this part of the app for about 2-3 years so don't know why it would stop working.

The code structure is:

Imports System.Net.Mail

Public Class Form1

    Private Sub SendEmail()
        Dim MS365Email As New MailMessage
        MS365Email.To.Add("RECIPIENTEMAIL")
        MS365Email.From = New MailAddress("SENDEREMAIL")
        MS365Email.Subject = "SUBJECT"
        MS365Email.IsBodyHtml = True
        MS365Email.Body = "BODYTEXT"

        Dim MS365client As New SmtpClient("smtp.office365.com", 587)
        MS365Email.Priority = MailPriority.Normal

        MS365client.EnableSsl = True
        MS365client.UseDefaultCredentials = False
        Dim xms365 As New Net.NetworkCredential("USERNAME", "PASSWORD")
        MS365client.Credentials = xms365
        MS365client.DeliveryMethod = SmtpDeliveryMethod.Network
        MS365client.SendAsync(MS365Email, Nothing)
    End Sub

End Class

Thanks for any help and suggestions.

JP

CodePudding user response:

Exactly the same happened to me.
I had the following exception:

Authentication unsuccessful, SmtpClientAuthentication is disabled for the Tenant.
Visit https://aka.ms/smtp_auth_disabled for more information.

You have to allow SMTP for the account (again).
Use Exchange Online PowerShell to enable or disable SMTP AUTH on specific mailboxes.

This example enables SMTP AUTH for mailbox [email protected].
Set-CASMailbox -Identity [email protected] -SmtpClientAuthenticationDisabled $false

Outlook/Apps failing sending mails? Microsoft has disabled SMTP (July 2022)

  • Related