Windows Subsystem for Linux: Use Functions to Operate Outlook

You can invoke Microsoft Outlook with command line switches to perform specific operations such as to compose an email and attach a file.

In Windows Subsystem for Linux, you can define a variable to store the location of the outlook executable and aliases or functions to call it. Functions seem to make it easier for me to quote values and are the only way to process command line arguments. Anything much more complicated than these examples likely belongs in a script rather than an alias or a function, and scripts let commands invoke commands where aliases and functions are for interactive sessions.

#hard-coded location of Outlook binary
outlook="/mnt/c/Program Files/Microsoft Office/root/Office16/OUTLOOK.EXE"

# Open or re-open Outlook 
# with gmail profile
# $@ passing any additional command line arguments
# & in the background
function og() { "$outlook" /profile gmail /recycle $@ & };

# convert first argument to windows path and attach
function oa() { file=`wslpath -w "$1"` ; shift ; "$outlook" -a "$file" $@ & };

# compose
function om() { "$outlook" /c ipm.note $@ & };

# compose to email address specified as first argument
function ot() { "$outlook" /c ipm.note /m "$@" & };

# attach first argument and compose to email to second argument
function oat() { file=`wslpath -w "$1"` ; shift ; "$outlook" -a "$file" /m $@ & };

Remember invoke or type commands command names such as oat before defining aliases or functions in order to avoid unintentionally overriding existing features.

Console showing which and type output

Define the functions at initialization:

With these functions, it is your responsibility to pass the correct arguments in the correct order.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: