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 \
I have written a shell script to send with mutt
an HTML message with embedded images rather than linked ones.
Several steps:
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:\2@example.com",g' < "$1" > "$DIR/$F"
neomutt -e 'set smtp_url=""' -e 'set sendmail="mysendmail"' -e "set content_type=text/html" me@example.com -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: <\1@example.com>,' < /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.