VB.NET - Email code does not work with Office 365

SuperCoder 136 Reputation points
2023-02-07T17:25:21.6366667+00:00

The code below has been used successfully for awhile, but we recently discovered that it is not compatible with Office 365. We need to modify the code but we don't know where to start (online searches were not helpful). Could someone please point us to where we can obtain information about this? Thank you.

Private Sub btnEmail_Click(sender As Object, e As EventArgs) Handles btnEmail.Click

        Dim EmailAddress = GetEmailAdress("RF", FPMain.txtFAcct2.Text)

        Dim Outlook As New Outlook.Application
        Dim Mail As Outlook.MailItem
        Dim Acc As Outlook.Account

        Outlook = New Outlook.Application()
        Mail = Outlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
        Mail.To = EmailAddress
        Mail.Subject = "Compliance Requirements"

        For Each Acc In Outlook.Session.Accounts
            'Select Case CaseCaseCasefirst pop3 For instance.
            If Acc.AccountType = Microsoft.Office.Interop.Outlook.OlAccountType.olPop3 Then
                Mail.Sender = Acc
            End If
        Next

        'Attach files
        Dim AttachmentDoc = GetDocPath() & "temp\" & FPMain.txtFAcct2.Text & ".pdf"

        Mail.Attachments.Add(AttachmentDoc)

        ' Code below over writes the signiture

        'Dim Body = "Please complete these compliance items or a giant green troll will eat you."
        'Mail.HTMLBody = Body

        Mail.Display()

    End Sub
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,570 questions
{count} votes