Sending email using Outlook in net standard 2.0 or net 5.0+

-- -- 957 Reputation points
2022-01-03T20:00:54.277+00:00

Hi

Is there a way to send email via Outlook in net standard 2.0 or net 5.0+, as was possible in net framework using code such as below at the end?

We need to use Outlook to make sure a copy of the mail is left in the Sent Items. We are on Exchange Online. Are we better off programmatically connecting directly to Exchange online and send from there? If so, is there an example of connecting to the same mailbox on Exchange Online as the Outlook profile mailbox on desktop?

Thanks

Regards

        Const olMailItem As Integer = 0
        Dim eto As String
        Dim esubject As String
        Dim emessage As String
        Dim OutlookApp As Object
        Dim OutlookAppMsg As Object
        Dim NS

        On Error Resume Next
        OutlookApp = GetObject(, "Outlook.Application")
        On Error GoTo 0
        If OutlookApp Is Nothing Then
            OutlookApp = CreateObject("Outlook.Application")
        End If

        Dim Session As Object
        Session = OutlookApp.GetNamespace("MAPI")
        Session.Logon()

        OutlookAppMsg = OutlookApp.CreateItem(olMailItem)
        With OutlookAppMsg
            .To = Email
            .Subject = "This is subject"
            .HTMLBody = "Blah Blah"

            OutlookAppMsg.display()
        End With

        OutlookAppMsg = Nothing
        OutlookApp = Nothing
        NS = Nothing
Outlook Windows Classic Outlook for Windows For business
Exchange Exchange Server Development
0 comments No comments
{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.