vbaoutlookvstooutlook-2019

Outlook/VBA/VSTO: How can I set the folder to store e-mail after being sent?


I created an automation script that's creating e-mails from a template e-mail file (.oft) and saving them to the Drafts folder for me to eventually send them manually.

In Outlook I set an option to store files in the same folder on reply/forward:

Outlook e-mail settings

Apparently, when I originally created the template e-mail file from an e-mail stored in a folder, that folder location was stored along with the template. This is very nifty, because now, after sending the e-mails I created from the template, these are stored in that original folder location.

This brings the following question to my mind:

Can I set this folder location in VBA when creating an e-mail message from the template, so I can programatically determine where to store an e-mail after it has been manually sent?


Solution

  • Of course - set MailItem.SaveSentMessageFolder property. See https://learn.microsoft.com/en-us/office/vba/api/outlook.mailitem.savesentmessagefolder