Send email using command Line
This answer is over 11 years old, these days I use python's import ezgmail for a 4 line plug, auth and play solution
Create a file named tmp.html with the following contents:
<b>my bold message</b>
Next, paste the following into the command line (parentheses and all):
(
echo To: [email protected]
echo From: [email protected]
echo "Content-Type: text/html; "
echo Subject: a logfile
echo
cat tmp.html
) | sendmail -t
The mail will be dispatched including a bold message due to the <b> element.
Shell Script
As a script, save the following as email.sh:
ARG_EMAIL_TO="[email protected]"
ARG_EMAIL_FROM="Your Name <[email protected]>"
ARG_EMAIL_SUBJECT="Subject Line"
(
echo "To: ${ARG_EMAIL_TO}"
echo "From: ${ARG_EMAIL_FROM}"
echo "Subject: ${ARG_EMAIL_SUBJECT}"
echo "Mime-Version: 1.0"
echo "Content-Type: text/html; charset='utf-8'"
echo
cat contents.html
) | sendmail -t
Create a file named contents.html in the same directory as the email.sh script that resembles:
<html><head><title>Subject Line</title></head>
<body>
<p style='color:red'>HTML Content</p>
</body>
</html>
Run email.sh. When the email arrives, the HTML Content text will appear red.
Related
mail, for exampleheirloom-mailxandbsd-mailxon Debian jessie. If amailcommand from an answer here doesn't work for you, you're probably using the wrongmail. Refer to your distribution's package manager to install the correct package, and use the specific name of that binary (e.g.bsd-mailxon Debian) to resolve that issue. More details on this here: heirloom.sourceforge.net/mailx_history.html