Is there a way to embed images into the body of an email using linux commands like mutt
or sendmail
?
I used this
mutt -e 'set content_type="text/image"' \
[email protected] -s "TEST" \
-i image001.jpg < data.txt
but it's not working.
I have written a shell script to send with mutt
an HTML message with embedded images rather than linked ones.
Several steps:
<img>
tags in the original HTML,src
url to a cid
,(neo)mutt
sendmail
Here's the main script which takes the HTML filename as argument (no checks performed, please do not consider it as an alpha software):
#!/bin/bash
F=$(basename "$1")
DIR="/tmp/inlinizer-$$/"
mkdir -p $DIR/Img
grep "src=" "$1" | sed -e "s,.*src=\"\([^\"]*/\)*\([^\"/]*\)\".*,wget \1\2 -O $DIR/Img/\2," > $DIR/get_img.sh
bash $DIR/get_img.sh
sed -e 's,src="\([^"]*/\)*\([^"/]*\)",src="cid:\[email protected]",g' < "$1" > "$DIR/$F"
neomutt -e 'set smtp_url=""' -e 'set sendmail="mysendmail"' -e "set content_type=text/html" [email protected] -s "test" -a $DIR/Img/* < "$DIR/$F"
One also needs a custom sendmail command (mysendmail
in the above) which post-processes the e-mail file generated by mutt
:
sed -e 's,Content-Disposition: attachment; filename="\([^"]*\)",Content-Disposition: inline; name="\1"\nContent-ID: <\[email protected]>,' < /dev/stdin | sed -e 's,Content-Type: multipart/mixed;,Content-Type: multipart/related;,' | sendmail $*
I have tested it in GMail and a few other webmails. Reports of problems with mail clients or webmails welcome.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With