You can use the mailto URL scheme to construct an email link containing a predefined message body, then call it from the command line, which should open it in your default email client. For example:
start mailto:?body=Your%20message%20here
Just customise the part after body=
at the end. I've read that the text needs to be URL-encoded, but at least in Windows Live Mail 2012 that doesn't seem to be necessary. I didn't try with longer texts or special symbols, though, and I don't have any other email clients (Outlook, Thunderbird, etc.) to test with.
For constructing that command, you could write a simple batch file, such as the following one:
@echo off
set /p text=
if "%text%" == "" goto error
start mailto:?body=%text%
goto end
:error
echo No argument provided!
:end
However, with that you do need the text to be URL-encoded, so you might want to do the whole thing in PowerShell. To URL-encode a string, you can use this:
[System.Reflection.Assembly]::LoadWithPartialName("System.Web") | out-null
[System.Web.HttpUtility]::UrlEncode("Your message here")
(The first line is needed to load the System.Web
namespace where the HttpUtility.UrlEncode
function lives.)
In fact, if your command (or whatever you have that produces the text you want to redirect) isn't too complex, you can just write the following one-liner in PowerShell (replacing <your-command-here>
with the actual command you're using):
start ("mailto:?body={0}" -f [System.Web.HttpUtility]::UrlEncode(<your-command-here>))
Note: this assumes that you just want to redirect text to your default email client. If you want to actually send emails from the command line, then look at @allquixotic's answer.
2Nitpicking: clip in your examples is not a device, it's a program named
clip.exe
– wmz – 2012-09-11T16:25:23.770@wmz Everything counts! Thanks, I'll correct it. – Alpha – 2012-09-11T18:48:01.497