skip to content

MessageSave API


MessageSave offers an API enabling custom scripts or applications to be invoked on every saved message. This API significantly simplifies the task of processing email messages. No longer do you have deal with intricacies of interfacing with Outlook. You can develop a simple script, which acts on a single message file and MessageSave will do the heavy lifting.

You can use MessageSave API for things like:

  • Automatic processing of incoming orders.
  • Importing email messages into a content or document management system.
  • Print messages.
  • Anything else that requires processing Outlook email messages with a custom script.

API scripts can be run whether you invoke MessageSave manually or automatically (AutoSave, Scheduler, Rule).

See also

See Saving Outlook Messages Chapter in the User Guide for various ways to run MessageSave.

API Description

MessageSave passes two types of information to the scripts:

  1. File name of the saved message. It is passed as the first and only command line argument to the script.
  2. Additional information about the message, passed in environment variables.

Saved File Name

Saved file path is passed to your script as the first and only command line argument. The way you access that value depends on the language you use to develop the script. For example:

  • In a batch file - %1
  • In a VB Script - Wscript.Arguments(0)
  • In C# - args[0]
  • In Python - sys.argv[1]

If you are using a different language, refer to the programming manual.

Additional Arguments

The following environment variables are available.

Environment variable name Description
TH_SENDER_EMAIL_ADDRESS Message sender email address.
TH_SENDER_EMAIL_ADDRESS_SMTP Message sender SMTP email address.
TH_SENDER_NAME Message sender name.
TH_SUBJECT Message subject.
TH_NORMALIZED_SUBJECT Normalized message subject.
TH_HASATTACH “Y” if the message has attachments, “N” otherwise.
TH_FOLDER_PATH Folder name.
TH_MESSAGE_DATE Message received date.
TH_MESSAGE_TIME Message received time of day.
TH_INVOCATION_ID Files saved during the same operation have the same value.

How to invoke your script

In order to have MessageSave invoke your script, simply enter the full path to the script in the Execute field of the Actions tab in the Edit Profile Window.


If you use a script to write to a CSV file, please keep in mind that if you open the file in Excel, Excel will lock it and your script will not be able to write to it. Be sure to close Excel before running scripts.


Here are a few simple examples written in VB Script. You can use them as a starting point for your own development.

Extract sender names and email addresses from your mailbox

This script creates a comma-separated value (CSV) list of names and email addresses of senders for all messages in your mailbox.

Generated File format: “Sender name”, “Sender email address”


Create a list of messages in your mailbox

This script creates a comma-separated value (CSV) list of messages in your mailbox.

File format: “Sender name”, “Sender email address”, “Subject”, “Has Attachment”, “Date”, “Time”, “Message ID”


Save all messages in a single file

Core MessageSave functionality saves every message in its own file. With this simple script, you can save all messages together in a single file. Use it with TXT and EML formats.


Convert Outlook messages to mbox format


MessageSave supports MBOX format natively. This script is provided as an illustration of the MessageSave API.

This simple script can convert Outlook messages or folders to mbox format used by email clients, such as Mozilla Thunderbird.


The script saves the mbox file as “outlook.mbox” on your Desktop.

We’d love to hear from you

With the sample scripts above, we have just scratched the surface of what custom MessageSave scripts are able to do. If you have ideas for new scripts, or if you have developed a script and would like to share it with other MessageSave users, please let us know.