Issue:
-----------------------------------------------------------------------------------------------------------------------
Send mail with attachment from command line in unix/linux
Linux 下如何发送带附件的邮件
Solution:
-----------------------------------------------------------------------------------------------------------------------
如果你可以使用 X window, 那么可以用 netscape 的
mail,也可以使用 kmail, 如果有的话。
如果这两个都不能用, 那么可以用 mail命令。
如果你能确认你的邮件服务器支持 8-bit 的字节,
可以直接用
cat ; | mail
;
不过很多邮件服务器不支持 8-bit 字节,
所以最好使用 uuencode 命令。
先写好邮件, 比如叫 mymail, 然后
uuencode ;
;
>;>; mymail
或者
cat ; | uuencode
;
>;>; mymail
然后编辑你的 mymail 文件, 在前面写上信的正文。
然后寄出。
收到信后, 把信中属于 mymail 的部分拷贝出来,
存为 themail.uue。如果对方是在 windows 下, 就可以用
winzip 7.0 解压, 即可得到附件。如果对方在 Linux
下, 可以用 uudecode 还原:
uudecode -o ;
themail.uue
cat ; | mail
;
如果有多个文件要处理,
那么就重复执行上述步骤,
不过这样收到邮件后对每个邮件需要分别处理。
当然压缩一下会得到更好的效果,
这样邮件长度会大大降低。时附件文件名就是压缩后的文件名。
方法1.uuencode file1 file1 | mail -s "title" mail@address
方法2.cat mailcontent.txt | mutt -s "title" -a attachfile1
mail@address
Discussion:
-----------------------------------------------------------------------------------------------------------------------
[root@linux ~]#[利用 uuencode 編碼 ] | [利用 mail
寄出去]
[root@linux ~]#uuencode [實際檔案] [信件中的檔名] | mail
-s '標題' email ###这里uuencode有两个参数,一般情况下容易犯的错误是只加一个参数(也就是文件的path),而不加”信件中的档案名“,所以命令就会hang在那里,按Ctrl+C后,你会收到邮件,但是没有附件。
範例一:將 ~/.bashrc 以附件夾帶的方式寄給
dmtsai
[root@linux ~]# uuencode ~/.bashrc bashrc | mail -s 'test encode'
dmtsai
http://www.cnblogs.com/lettoo/archive/2010/10/14/1850934.html
If you look at <
cookbook>> chapter 15.15
<
Script>>, you will find very detailed
instruction on this topic
-----------------------------------------------------------------------------
uuencode, uudecode—encodes a binary file into ASCII text
in order to send it through e-mail, or converts it back into its
original formuuencode[ source–file ] file–label
uudecode [ encoded–file ]
uuencode converts a binary file into an ASCII-encoded
representation that can be sent using mail. The label argument
specifies the output filename to use when decoding. If no file is
given, stdin is encoded. uudecode reads an encoded file, strips off
any leading and trailing lines added by mailer programs, and
re-creates the original binary data with the filename and the mode
and owner specified in the header. The encoded file is an ordinary
ASCII text file; it can be edited by any text editor. But it is
best only to change the mode or file label in the header to avoid
corrupting the decoded binary.
Example A.68.
1 uuencode mybinfile decodedname >
uumybinfile.tosend
2 uudecode uumybinfile.tosend
EXPLANATION
The first argument, mybinfile, is the existing file to be
encoded. The second argument is the name to be used for the
uudecoded file, after mailing the file, and uumybinfile.tosend is
the file that is sent through the mail.
This decodes the uuencoded file and creates a filename as given
as the second argument to uuencode.