Sending a file as the body of an email

I want a utility that does something like this:

email --subject="message" --body=body.txt --to=to_address@hostname.com

(using pre-configured sender information for e.g. gmail). Note that body.txt is plain text and should be the body of the message, not an attachment. If the body is omitted it should pop up an editor and let me type in my message that way.

I could hack together a quick script that does this, but I was wondering if there’s an easy way to do this with common unix tools?

Answer

The mail/mailx utilities do most of what you want. What it does not do, is open an editor on empty contents. The body of the email is read through stdin. Here is an example on usage:

mail -s "message" to_address@hostname.com < body.txt

Attribution
Source : Link , Question Author : Ismail Badawi , Answer Author : jordanm

Leave a Comment