I'm currently using mailx to send html formated mails from my scripts :
cat body.html | /usr/bin/mailx -a "From: Me <me@domain>" -a "Content-type: text/html" -s "My subject" $RECIPIENTS
Now I'd like to add an attachement (png image) but I cannot figure out how. I'd like to try with mailx before moving to mutt or something else. Thanks a lot
If your requirements are simple, you can use bare Sendmail. It is not something I particularly recommend, but since you wanted to avoid mutt
...
# Now that we actually concatenate two files (well, stdin and a file),
# we are no longer eligible for a Useless Use of Cat Award
( cat - body.html <<HERE
Subject: My subject
Mime-Version: 1.0
Content-type: multipart/related; boundary="foooobar"
--foooobar
Content-type: text/html
HERE
cat <<HERE
--foooobar
Content-type: image/png
Content-disposition: inline
Content-transfer-encoding: base64
HERE
base64 image.png
echo; echo '--foooobar--' ) | sendmail -oi $RECIPIENTS
I do wish there were a simple, standard utility for this, but alas, instead there are many, all more or less mutually incompatible and murky. Again, if you can use mutt
, that's probably the most widely supported and standard tool you can hope for.
Try this:
uuncode input_file2.jpg attachment2.jpg >>tempfile
cat tempfile | mailx -s "subject" <email>
Uuencode reads file (or by default the standard input) and writes an encoded version to the standard output. The encoding uses only printing ASCII characters and includes the mode of the file and the operand name for use by uudecode. If name is /dev/stdout the result will be written to standard output. By default the standard UU encoding format will be used. If the option -m is given on the command line base64 encoding is used instead.