VBA Outlook - Ways to send email from a specific email account

Early Binding 

Dim oApp as Outlook.Application

Dim oEmail as Outlook.MailItem

Dim oNS as Outlook.NameSpace

Set oApp=New Outlook.Application

Set oEmail=oApp.CreateItem(olMailItem)

Set oNS=oApp.GetNamespace("MAPI")  'Messaging Application Programming Interface

oEmail.SendUsingAccout=oNS.Accounts.Item(1) 'To send email from a specific account.

Or Use

With oEmail

    .SentOnBehalfOfName="Enter the specific account email-id."

end With


Late Binding

Dim oApp as Object

Dim oEmail as Object

Dim oNS as Object

Set oApp=CreateObject("Outlook.Application")

Set oEmail=oApp.CreateItem(0)

Set oNS=oApp.GetNamespace("MAPI") 'Messaging Application Programming Interface

oEmail.SendUsingAccount=oNS.Accounts.Item(1) 'To send email from a specific account.

Or Use

With oEmail

    .SentOnBehalfOfName="Enter the specific account email-id."

end With

Comments

Popular posts from this blog

Power Automate - Automatically fetch data from Power BI in to Excel and Send the copy of the Excel file via Email

Separate Text (Characters) & Numbers from Alpha Numeric String Using Formula and Macro (VBA)

File System Object