2

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


  • Have a look HERE - Dinesh
  • @Dinesh That's not a very good answer. HTML and uuencode is not a sane combination. - tripleee

2 답변


1

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.


  • Thanks tripleee, however (and this is a different problem) when using sendmail, the mail gets into junk on the (gmail) recipient box. - user2683188
  • That's probably a function of your content, not of the program you used to send it. - tripleee

1

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.


  • Although the code is appreciated, it should always have an accompanying explanation. This doesn't have to be long but it is expected. - peterh
  • the commands mentioned in the comment can be easily checked before being executed, I do not see what needs to be explained further, as the user asking is already using mailx, and aware of "cat". uunicode, can be manned easily - Ron
  • Is this better? - Ron

Linked


Related

Latest