MessageSave offers an API enabling external 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 to write code to iterate over Outlook folders and messages. 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 Saving Outlook Messages Chapter in the User Guide for various ways to run MessageSave.
MessageSave passes two types of information to the scripts:
- File name of the saved message. It is passed as the first and only command line argument to the script.
- 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 -
- In a VB Script -
- In C# -
- In Python -
If you are using a different language, refer to the programming manual.
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_NORMALIZED_SUBJECT||Normalized message subject.|
|TH_HASATTACH||“Y” if the message has attachments, “N” otherwise.|
|TH_MESSAGE_DATE||Message received date.|
|TH_MESSAGE_TIME||Message received time of day.|
How to invoke your script¶
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.