Command line for mailto:

xirtam

Diamond Member
Aug 25, 2001
4,693
0
0
Hey, I need to figure out how to access the windows default mailer from the command prompt. I want to duplicate what happens when you access the run command from the start menu and type "mailto:user@domain.com". Any ideas?
 

RSMemphis

Golden Member
Oct 6, 2001
1,521
0
0
explorer "mailto:user@domain.domainext"

works.
Note that that opens an explorer window AND a mail window, so it may not be what you want.
 

tritium4ever

Senior member
Mar 17, 2002
402
0
71
I've got a method that won't pop up any unnecessary windows. Even better, you can automate the process if you follow the instructions to the end!

In the command prompt, type:

start mailto:[user]@[domain].[domain type]?subject="[subject]"

For example, the following command:

start mailto:billgates@microsoft.com?subject="Please for the love of god remove Windows Product Activation!"

would start up your default email program, start a new message to billgates@microsoft.com with Please for the love of god remove Windows Product Activation as the topic.

Things get even better if you're familiar with DOS batch file scripting. Create a new file called sendmail.bat (or anything you like with the .bat extension) and enter in the following line:

start mailto:%1?subject="%2"

See the %1 and %2 symbols? They represent command line arguments. So if you typed in the following on the command line:

sendmail billgates@microsoft.com DIE!

the first argument (billgates@microsoft.com) would be mapped to the %1 symbol and the second argument (DIE!) would be mapped to the %2 symbol. It would be the equivalent of typing in start mailto:billgates@microsoft.com?subject="DIE!" into the command line.

The problem with the above batch file is that it only accepts a single argument for the subject, meaning you can only use a single word for the subject. To get around that, revise the batch file so that it contains the following lines:

@echo off
start mailto:%1?subject="%2 %3 %4 %5 %6 %7 %8 %9"


You notice that symbols for an additional 7 arguments (%3 to %9) have been added. This allows you to use an extra 7 words for the subject. Now you may be wondering why you can't extend that to %10 and beyond, and the answer is simple. The batch file scripting system only allows a maximum of ten arguments to be used, so going past %9 is impossible. Which brings up another question: what happened to %0? Well, %0 returns the very first argument in a command, and since the first thing you type is sendmail to run the batch file, sendmail will be mapped to %0, making it useless. What you may also notice from above is the line with @echo off. What this does is suppress the command from being shown in the command prompt. You can take it out, but then every time you run the batch file another line, the command prompt will "echo" the entire command to the prompt again, which is mildly annoying...after all, you don't need to see what you've just typed.

One little note: if you don't use all of the arguments available for the subject (ie your subject is less than 8 words long), then spaces will automatically be mapped to the unused arguments. This results in some extra spaces at the end of the topic, but it's not a big deal. There's a way around this little "issue" but the solution occupies many more lines and isn't really that important.

Now the final step is to copy that new batch file into your Windows directory (I'm old school and I like to call it a directory, not a folder. Long live directories!). Since Windows automatically creates a path to the Windows directory, you can call up your little batch file from any directory on your hard drive, even if you're currently in the directory of another drive! Now you have a powerful command line-based way to launch your email program!

PS: If you find the above information to be useful, please send me an email using your new batch file! My email is wong DOT chris AT rogers DOT com.