How to send html-formatted email

Short answer: sending .html-formatted email is rather easy, even from a local laptop. But there can be difficulties, which are not avoided easily. To begin with, the short and (hopefully) working answer:

Mac OS | CentOS | Debian

cat letter.html | mail -s "$(echo -e "Testing email\nContent-Type: text/html")"

Make sure you check the SPAM folder, as it has nearly 0 chance of getting through to your mailbox from scratch. If it doesn’t work out, you’ll have to go deeper.

Modern email is one of the oldest and reliable ways of communication, but one of the most exploited too. That’s why chances are that your email will be rejected by spam filters (especially if you abuse this method and send it to different addresses to debug the appearance in different email providers).

Email is rather simple, but few things can help if command above failed to deliver email to you. You can specify From and Reply-To headers with:

cat letter.html | mail -s "$(echo -e "Testing email\nFrom: user@localhost.localdomain\nContent-Type: text/html")"

If you happen to know your domain name. Static IP might also help. If not, it is time dive into mail command and to spend some time finding out, why your email is getting rejected.