Send HTML email from command line

[problem]

Need to send an email from UNIX command line, that contains HTML content?

[/problem]

[solution]

Most useful when generating statistics, etc – just spin round and spit out HTML table rows, through sendmail.

[/solution]

[example]

Here is the code:


/usr/lib/sendmail -t
To:[email protected]
From:[email protected]
Subject:This is a test
MIME-VERSION:1.0
Content-Type: multipart/mixed; boundary="gc0y0pkb9ex"

--gc0y0pkb9ex
Content-type: text/html;charset="iso-8859-1"

<html><head><title>Test HTML mail</title></head>
<body>
<table border=1>
<tr><td align=center>test mail</td></tr>
<tr><td>This is an HTML email sent from UNIX command line!</td></tr>
</table>
</body></html>
.

[/example]

[reference]

[tags], Unix Coding School[/tags]

[/reference]

If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

Your email address will not be published. Required fields are marked *