Link to home
Start Free TrialLog in
Avatar of FlorisMK
FlorisMKFlag for Netherlands

asked on

Set Email Account for New Message From VBA

For convenience, I want to create a button in Outlook that creates a MailItem and sets some properties. Specifically, I want to have a button for creating a private email message. The code should:
1 - Create a new message.
2 - Set the BodyFormat to plain text.
3 - Set the email account to my private account.
4 - Display the new message with the focus set to the Body textbox.
Number 3 has me stumped. It seems Outlook doesn't expose the selected email account for a MailItem in its object model. Any ideas? (SendKeys is not an option.)

Public Sub CreatePrivateEmail()
   Dim eml As Outlook.MailItem
   Set eml = ThisOutlookSession.CreateItem(olMailItem) '               1
   With eml
      .BodyFormat = olFormatPlain '                                               2
      'Code to set the selected account to my private email account   3, no idea how to do it
      .Display '                                                                              4
   End With
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Rob132332
Rob132332
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the points.
Avatar of anywaste
anywaste

I haven't tried this, but this web page:(http://vbaadventures.blogspot.com/2008/03/automatic-email-account-assignment-in.html) seems to suggest that you can change the account using something called the "Redemption COM Library".
Avatar of FlorisMK

ASKER

Brilliant, anywaste! That's excellent news! I've posted a request on CS to award you points. However did you find this question?
I'm posting points for you in this topic; easier than reopening, CS tells me :-)