Home > Net >  how to set an Account object by MailItem.SendUsingAccount when sending an email?
how to set an Account object by MailItem.SendUsingAccount when sending an email?

Time:09-29

I need to build a program that automatically sign in to Outlook and send an email using the account.

The doccument says SendUsingAccount property is available to set an Account object from which a mail is sent, yet it seems not explain how.

Please help me to find how to do it. Thank you!

CodePudding user response:

The other account should be configured in Outlook, for example, here is a VBA sample code:

Sub SendUsingAccount() 
 Dim oAccount As Outlook.account 
 For Each oAccount In Application.Session.Accounts 
   If oAccount.AccountType = olPop3 Then 
     Dim oMail As Outlook.MailItem 
     Set oMail = Application.CreateItem(olMailItem) 
     oMail.Subject = "Sent using POP3 Account" 
     oMail.Recipients.Add ("[email protected]") 
     oMail.Recipients.ResolveAll 
     Set oMail.SendUsingAccount = oAccount 
     oMail.Send 
   End If 
 Next 
End Sub
  • Related