这个脚本要依赖于sendmail和uuencode, 不过linux默认已经安装上这两个程序了。
怎么样使用?
邮件内容可以写成一文本文件
#!/usr/bin/perl
if ( $#ARGV < 0)
{ print "Usage: mailattach.pl ","\n"; exit(0); }
$touser = $ARGV[0]; $fromuser = $ARGV[1]; $subject = $ARGV[2]; $file = $ARGV[4];
print $file;
open(MAILFILE, "$ARGV[3]") || die "can not open mail file" ; @mailcont = <MAILFILE>; close(MAILFILE);
$yourmail = "$touser\@alcatel-lucent.com";
open(MAIL, "|/usr/lib/sendmail -t $yourmail") || return 0; select (MAIL); print << "EOF"; To: $touser\@alcatel-lucent.com From: $fromuser\@alcatel-lucent.com Subject: $subject
@mailcont
EOF
if ( $file ne "" ) { # File to send to user
open(FILE, "uuencode $file $file |") or die; while( <FILE>) { print MAIL; }; close(FILE); } #and finish sending the mail
close(MAIL);
|
阅读(1504) | 评论(0) | 转发(0) |