Linux文本模式下发送带附件的Email

最近写一个脚本,需要直接在linux文本终端里面直接发送附件,而linux自带的那个什么mail命令,是由mailx包生成的,本身不带发送附件的功能。

放狗搜了一圈,发现基本上使用的都是mailx+uuencode这招。详情见http://www.webjx.com/server/linux-2724.html”

但是这种方式,是将文件转成ASCII码进行传输,在某些客户端(比如某些web客户端),很可能收到的就是一堆乱码。为了解决这个问题,我推荐另一个文本模式的邮件客户端:nail

不知道centos的官方源中有没有,但是,在rpmforge的源里面是肯定有的。装好之后,本身只会生成/usr/bin/nail这个命令,要是你很习惯用mail这个命令的话,可以考虑自己建立一个软链。

另附rpmforge源中nail包的information

# yum info nail
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * addons: centos.ustc.edu.cn
 * base: centos.ustc.edu.cn
 * extras: centos.ustc.edu.cn
 * rpmforge: ftp-stud.fht-esslingen.de
 * updates: centos.ustc.edu.cn
Installed Packages
Name       : nail
Arch       : x86_64
Version    : 12.3
Release    : 4.el5.rf
Size       : 612 k
Repo       : installed
Summary    : Enhanced implementation of the mailx command
URL        : http://nail.sourceforge.net/
License    : BSD
Description: Nail is an enhanced mail command, which provides the functionality
           : of the POSIX mailx command. It is derived from Berkeley Mail.
           :
           : Additionally to the POSIX features, nail can work with Maildir/ e-mail
           : storage format (as well as mailboxes), supports IMAP, POP3 and SMTP
           : procotols (including over SSL) to operate with remote hosts, handles mime
           : types and different charsets. There are a lot of other useful features,
           : see nail.html in the documentation.
           :
           : And as its ancient analogues, nail can be used as a mail script language,
           : both for sending and receiving mail.

在CentOS5.1下安装SquirrelMail出现”(13 : Permission denied)”

如图:
1

百思不得其解,实在我的IMAP工作是正常的,而且我用thunderbird也可以连接上

监看/var/log/maillog时发现,squirrelmail在登陆时,log并不记录

临看/var/log/message时,发现这个时候写入了这么一条记录

kernel: audit(1208928634.263:213): avc:  denied  { name_connect } for  pid=12046 comm="httpd" dest=143 scontext=root:system_r:httpd_t:s0 tcontext=system_u:object_r:pop_port_t:s0 tclass=tcp_socket

可见这个登陆信息并没有提交到IMAP。

于是,google下面关键词:

squirrelmail 13  Permission denied

找到这么一解决方法:
原来是要输入这么一条命令:

setsebool -P httpd_can_network_connect=1

原来又是SELinux的权限问题
现在的SELinux异常强大啊
以后,没事还是学学SELinux,呵呵

另外,还是一句老话,建议所有的新手在学习还是禁用iptables与SELinux,减少一个故障点
不过,好像chkconfig iptables off 这个命令在CentOS或者RHEL 5.1里面都不生效了
每次我都要把iptables remove才会有效果。。。