# 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