Bash html mail

A classic combination!

To send an HTML email using Bash, you can use the mail command with the -a option to specify the HTML content. Here's an example:

mail -s "Subject" -a "Content-Type: text/html" [email protected] << EOF
<html>
  <body>
    <p>This is an HTML email!</p>
  </body>
</html>
EOF

This will send an email with the subject "Subject" to [email protected] with the HTML content enclosed in the << EOF block.

If you want to use a file as the HTML content, you can use the -A option instead of -a:

mail -s "Subject" -A "Content-Type: text/html" [email protected] < file.html

Make sure to replace file.html with the actual path to your HTML file.

Note that the mail command is not as powerful as modern email clients, and you may encounter issues with formatting or attachments. If you need more advanced features, consider using a tool like mutt or s-nail instead.

Also, be aware that some email clients may not render HTML emails correctly, especially if they're using a plain text-only client. To ensure compatibility, you can use a plain text fallback by adding a text/plain alternative to your HTML email:

mail -s "Subject" -a "Content-Type: multipart/alternative; boundary=\"---boundary---\"" [email protected] << EOF
---boundary---
Content-Type: text/plain

This is a plain text fallback.

---boundary---
Content-Type: text/html

<html>
  <body>
    <p>This is an HTML email!</p>
  </body>
</html>
---boundary---
EOF

This will send a multipart email with both a plain text and an HTML part. The recipient's email client can choose which part to display.