0
votes

i have a few accounts in outlook. one of them is an exchange account. others are IMAP

I am trying to use the IMAP one by default..the outlook options do not seem to help...because-->

I am using VBA code to load email content and trigger email send process from excel.

The emails keep going out using the exchange account even if i declare the IMAP account the default. Any ideas?

1

1 Answers

0
votes

The Outlook object model provides the SendUsingAccount property for the MailItem class which allows to set an Account object that represents the account under which the MailItem is to be sent. You just need to setup the property before calling the Send method. For example:

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 
      oMail.SendUsingAccount = oAccount 
      oMail.Send 
    End If 
  Next 
End Sub