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

SuperCoder 136 Reputation points
2023-02-07T17:16:07.1833333+00:00

We have been using the code below for awhile and recently found out that it is not compatible with the Office 365 version of Outlook. Could someone point me in the right direction to resolve this issue? 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,580 questions
{count} votes