How can I set the folder to store e-mail after being sent?

AxD 671 Reputation points
2025-03-11T17:03:57.1533333+00:00

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:

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?


Well Copilot answered my question now. However, there is one line I don't understand in the answer:

olMail.PropertyAccessor.SetProperty "http://schemas.microsoft.com/mapi/proptag/0x0E1F001E", entryID
  1. How is 0x0E1F001E related to PR_SENTMAIL_ENTRYID?
  2. Is there no easier, more "Intellisense-friendly" way to set this property?
Outlook | Windows | Classic Outlook for Windows | For business
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Q&A Assist
    2025-03-11T17:03:57.1633333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To set the folder location for storing an email after it has been sent in Outlook using VBA, you can use the PR_SENTMAIL_ENTRYID property. This property allows you to specify the folder where sent messages should be stored.

    Here’s a general approach to achieve this:

    1. Create the email from the template: Use the CreateItem method to create a new email item from your template.
    2. Set the PR_SENTMAIL_ENTRYID property: You can set this property to the entry identifier of the folder where you want to save the sent email.

    Here is a simplified example of how you might implement this in VBA:

    Sub CreateAndSendEmail()
        Dim olApp As Outlook.Application
        Dim olMail As Outlook.MailItem
        Dim olNamespace As Outlook.Namespace
        Dim olFolder As Outlook.Folder
        Dim entryID As String
    
        Set olApp = New Outlook.Application
        Set olNamespace = olApp.GetNamespace("MAPI")
        
        ' Specify the folder where you want to save the sent email
        Set olFolder = olNamespace.GetDefaultFolder(olFolderInbox).Folders("YourFolderName") ' Change to your folder name
        entryID = olFolder.EntryID
    
        Set olMail = olApp.CreateItemFromTemplate("C:\Path\To\YourTemplate.oft")
        
        ' Set the PR_SENTMAIL_ENTRYID property
        olMail.PropertyAccessor.SetProperty "http://schemas.microsoft.com/mapi/proptag/0x0E1F001E", entryID
        
        olMail.Subject = "Your Subject"
        olMail.To = "recipient@example.com"
        olMail.Send
    End Sub
    

    In this example, replace "YourFolderName" with the name of the folder where you want to store the sent emails, and update the path to your template file accordingly.

    This way, when you send the email, it will be saved in the specified folder.


    References:

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.