用mutt命令发送带附件的邮件

网上有很多帖子介绍了如何用mutt命令发送邮件,其中也有一并发送附件的命令。但这些命令实际上都会报错,在man mutt之后,恍然大悟。

man mutt里是这么说的:
-a file […]
Attach a file to your message using MIME. When attaching single or multiple files, separating filenames and recipient addresses with “–” is mandatory, e.g. mutt -a image.jpg — addr1 or mutt -a img.jpg *.png — addr1 addr2. The -a option must be placed at the end of command line options.

显然,这里有两点要注意:
1、-a参数必须放在最后
2、附件可以是多个,但不管是一个还是多个,只要加了附件,就必须用“ — ”跟收件人地址隔开。
貌似网上的教程都没有注意这两点。

另外,我还写了个shell脚本放在/usr/bin里,每次只要
sendfile [email protected] file1 file2 file3 ...

脚本点这里下载

01 #!/bin/bash
02
03 files=""
04 count=0
05 for arg in $*
06 do
07     if [ $count != 0 ]
08     then
09         files=$files"$arg "
10     fi
11
12     let "count=count+1"
13 done
14
15 echo -e "Hi,\nHere is the files.\n\nSincerely,\nMichael" | mutt -s "Files" -a $files$1

这段脚本的作用就是把第一个参数抠出来当作收件人,其他参数当作附件地址

Linux , , ,

6 comments


Leave a Reply to Vency Cancel reply

Your email address will not be published. Required fields are marked *