Question

What's the best way to send mail from the shell with one line of code?

mailx -s "subject" foo@bar.com

Enters into line by line entry of the body and the message is only sent with termination of Ctrl+D or '.'

Since I am accessing the system command through another program, I'd like to be able to do something like:

mailx -s "subject" foo@bar.com \n Body Text \n . 

in one go.

Thank you!

Was it helpful?

Solution

mailx -s "subject" foo@bar.com <<<$'\n Body Text \n'

OTHER TIPS

Thank you to both Alfe and Joachim PileBorg, I now have two solutions! The one Alfe provided works, as does:

echo "body" | mailx -s "subject" foo@bar.com 

which, though my Unix is rusty, I imagine does basically the same thing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top