Send an Email from the Windows Commmand Prompt or Script…

July 19th, 2012 by Jeremy Pavlov | Filed under Microsoft, Scripting, Windows 7.

Today, Avi and I were discussing one of the requirements of an application he’s working on;  it seemed simple enough at first blush…

He needed to send an email from a Windows 7 computer — which is fairly straightforward if you happen to have something like BLAT installed, or if you’re able to script a call to a nearby SMTP gateway.  However, there was one major requirement this time:  it had to appear to come from the *user* of the application, with the user’s intent/blessing/permission. 

Yes, Avi could have configured the application to make a direct call to the local email client executable — if there were guaranteed to be one (not necessarily the case), and if the version/type were to be predictable (it might be Outlook, it might be GroupWise, etc.) to properly call with the correct options and flags.  Avi did some digging and soon found a way to get a fully formatted message to launch in Outlook, but we had to modify it a tad to get it to work in both GroupWise and Outlook (and perhaps others).  Here’s what we settled on, and how it works…

Aside: I’ll have to assume that your GroupWise or Outlook is properly installed and configured for these things to work.

Let’s start with the basics (pun intended); this should launch your email client and pre-populate the recipient (interestingly, it should work no matter whether your email client is configured or not):

start mailto:sales@CoretekServices.com

…but you knew that, and you’re clearly not impressed.  Now perhaps the trickiest part: after the recipient in the command — and before the next component (I use Subject in this example) — it is best to use a question (?) mark here for Outlook *and* GroupWise compatibility, although a caret+ampersand (^&) will work if using Outlook only (note that the “%20” is a space character):

start mailto:sales@CoretekServices.com?Subject=Your%20Subject...

…and now you’re intrigued.  Let’s build on that.  Next, we tack on another option in the command (I show the CC option here), separated with a caret+ampersand (^&) :

start mailto:sales@CoretekServices.com?Subject=Your%20Subject...^&CC=questions@YourLinuxGuy.com

…and now I’ve won you over.  Cool!  Let’s complete the line — separated by more caret+ampersand (^&) characters, of course — and make it a fully populated email, ready-to-send:

start mailto:sales@CoretekServices.com?Subject=Your%20Subject...^&CC=careers@CoretekServices.com^&BCC=secret@CoretekServices.com^&Body=This%20is%20the%20message,%20which%20I%20agree%20to%20send%20by%20clicking%20SEND.

Now click send, and enjoy!

 

 

Did you like this? Share it:

Tags: , , , , , ,


Leave a Reply