sendmail或mail 发带附件

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 来测试一下时否正常,应该没问题,我已经试验过了

 

 

 

我也测试过,成功!还有如果加上主题如何做?谢谢!

 

 

 
我在BSD下面可以这样子,不知你的系统怎样

uuencode a.tar.gz a.tar.gz | mail -s "hello, send you an attach." somebody@foo.bar
 
 
 
 
 
 
 
分类: 未分类


#!/usr/bin/perl
# Set Variables
$mailprog = "/usr/lib/sendmail";
# Your Email Address
$youremail = "name\@domain.com";
# Your Name
$yourname = "Hilton";

# Email Address of the recver
$email = " recver@domain.com";
# Send file to user in email
open(MAIL, "|$mailprog -f $yourname -t $youremail") or die;
print "|$mailprog -f $yourname -t $youremail\n" ;
# Create headers
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 to send to user
$file = "file1";
open(FILE, "uuencode $file $file |") or die;
while( <FILE>) { print MAIL; };
close(FILE);
$file="file2";
open(FILE, "uuencode $file $file |") or die;
while( <FILE>) { print MAIL; };
close(FILE);
#and finish sending the mail
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


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值