使用linux命令在电子邮件中嵌入图像 [英] Embedding an image in an email using linux commands

查看:122
本文介绍了使用linux命令在电子邮件中嵌入图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用muttsendmail之类的linux命令将图像嵌入到电子邮件的正文中?

Is there a way to embed images into the body of an email using linux commands like mutt or sendmail?

我用了

mutt -e 'set content_type="text/image"' \
   u.mohan@6dtech.co.in -s "TEST" \
    -i image001.jpg < data.txt

但是它不起作用.

推荐答案

我编写了一个shell脚本,用mutt发送带有嵌入式图像而不是链接图像的HTML消息.

I have written a shell script to send with mutt an HTML message with embedded images rather than linked ones.

几个步骤:

  1. 下载通过<img>标记链接的原始HTML中的所有图像文件,
  2. 通过将src网址更改为cid,准备HTML文件,
  3. 使用(neo)mutt
  4. 准备多部分电子邮件
  5. 修复此电子邮件中的一些内容描述标签
  6. 发送sendmail
  1. download all image files linked by <img> tags in the original HTML,
  2. prepare the HTML file by changing the src url to a cid,
  3. prepare a multipart e-mail with (neo)mutt
  4. fix some content description tags in this e-mail
  5. send with sendmail

这是将HTML文件名作为参数的主脚本(不执行任何检查,请不要将其视为Alpha软件):

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"

还需要一个自定义sendmail命令(在上面为mysendmail),该命令对由mutt生成的电子邮件文件进行后处理:

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 $*

我已经在GMail和其他一些网络邮件中对其进行了测试.欢迎报告邮件客户端或网络邮件的问题.

I have tested it in GMail and a few other webmails. Reports of problems with mail clients or webmails welcome.

这篇关于使用linux命令在电子邮件中嵌入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆