mail -s "subject" xxxxx@gmail.com <test.html
works, but only for plain text email.
What is the correct way to send HTML email using the Linux command mail
?
emailhtmlmail-command
mail -s "subject" xxxxx@gmail.com <test.html
works, but only for plain text email.
What is the correct way to send HTML email using the Linux command mail
?
Best Answer
There are many different versions of
mail
around. When you go beyondmail -s subject to1@address1 to2@address2 <body
(for sending, that's all POSIX guarantees — and even-s
didn't exist in the old days), they tend to have different command line options. Adding an additional header isn't always easy.With some
mailx
implementations, e.g. frommailutils
on Ubuntu or Debian'sbsd-mailx
, it's easy, because there's an option for that.With the Heirloom
mailx
, there's no convenient way. One possibility to insert arbitrary headers is to seteditheaders=1
and use an external editor (which can be a script).With a general POSIX
mailx
, I don't know how to get at headers.If you're going to use any
mail
ormailx
, keep in mind thatmail
andmailx
.mail
andmailx
treats lines beginning with~
as commands. If you pipe text intomail
, you need to arrange for this text not to contain lines beginning with~
.If you're going to install software anyway, you might as well install something more predictable than
mail
/Mail
/mailx
. For example, mutt. With Mutt, you can supply most headers in the input with the-H
option, but notContent-Type
, which needs to be set via a mutt option.Or you can invoke
sendmail
directly. There are several versions ofsendmail
out there, but they all supportsendmail -t
to send a mail in the simplest fashion, reading the list of recipients from the mail. (I think they don't all supportBcc:
.) On most systems,sendmail
isn't in the usual$PATH
, it's in/usr/sbin
or/usr/lib
.