sendmail发附件问题
sendmail/mail 理论上在command line送信时只能传送文本文件。
你可以把二进制文件用 uuencode 编一下码,然后再发送。假设你有一个文件叫 a.tar.gz,你可以用:
uuencode a.tar.gz a.tar.gz | mail somebody@foo.bar
这样收信者收到后,存附件为x.tar.gz,接下来问题就有点不一样:
有些程序很聪明,可以直接解开它,比如 windows commander。大多数都不行,还需解码:
uudecode x.tar.gz
然后,相同目录下就会生成当时你所指定名字的文件 a.tar.gz,你可以用 tar 来测试一下时否正常,应该没问题,我已经试验过了
uuencode a.tar.gz a.tar.gz | mail -s "hello, send you an attach." somebody@foo.bar
# Set Variables
$mailprog = "/usr/lib/sendmail";
# Your Email Address
$youremail = "name\@domain.com";
# Your Name
$yourname = "Hilton";
open(MAIL, "|$mailprog -f $yourname -t $youremail") or die;
print "|$mailprog -f $yourname -t $youremail\n" ;
print MAIL "From: $yourname\n";
print MAIL "To: $email\n";
print MAIL "Subject: File: $file (uuencoded)\n";
print MAIL "Hi\n,this is Hilton\n";
$file = "file1";
open(FILE, "uuencode $file $file |") or die;
while( <FILE>) { print MAIL; };
close(FILE);
open(FILE, "uuencode $file $file |") or die;
while( <FILE>) { print MAIL; };
close(FILE);
close(MAIL);
sendmail发附件需要用uuencode命令这个命令在sharutils组件中,可以远程安装
apt-get install sharutils
yum install sharutils
服务器上用sendmail发送email很关键的一条是/etc/mail/sendmail.mc中应该包含
MAILER(local)
这个设置的意思是允许发送来自127.0.0.1的email
编辑好sendmail.mc,生成sendmail.cf文件
#m4 sendmail.mc > sendmail.cf
然后启动sendmail
#/etc/rc.d/init.d/sendmail start
现在就可以发送email了 ^_^
uuencode ~/abc.xls abc.xls | mail -s "abc" xxx@email.com