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

SuperCoder 236 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
Developer technologies | VB
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.