您的位置:首页 > 运维架构 > Linux

linux 发送邮件脚本

2011-10-24 19:09 411 查看
Linux发送邮件脚本


然后写一个脚本,如run.sh

  #!/usr/bin/bash

  mail -s "Title here" -c Address_CC Address_To < email.txt

测试可以用

run.sh

#!/bin/sh

date >>ftp.txt

echo ftp01>>ftp.txt

echo ===================================== >>ftp.txt

echo IP ADDRESS >>ftp.txt

ifconfig | grep "inet" | grep -v "127.0.0.1"|awk '{print $2}' >>ftp.txt

df -h >>ftp.txt

echo ====================================== >>ftp.txt

mail -s "FTP01" xxx@eee.cn <ftp.txt

rm ftp.txt

=============================================

指定邮件服务器发邮件 使用软件 pine-4.33

============================================================

Linux发送邮件脚本:

#!/usr/bin/perl

use Net::SMTP;

use MIME::Base64;

$filename_1 = `/bin/cat 邮件正文目录`;

chop($filename_1);

$boundary = "9876543210";

$user = $ENV{USER};

$from = $ENV{HOSTNAME};

$to = "收件人(显示)";

$subject="邮件主题";

####################################################################

$mime=''MIME-Version: 1.0

Content-Type: multipart/mixed; boundary=''.$boundary.''

Content-Transfer-Encoding: 8bit

--''.$boundary.''

Content-Type: application/octet-stream; name="''.$filename1.''"

Content-Transfer-Encoding: base64

Content-Description: ''.$filename.''

Content-Disposition: attachment; filename="''.$filename1.''"

'';

#open(FILE, "<$filename") or die "$!";

$smtp = Net::SMTP->new(''邮件服务器IP'');

$smtp->auth("邮件帐号","密码");

$smtp->mail(''发件人地址'');

$smtp->to(''收件人地址'');

$smtp->data();

$smtp->datasend("From: 发件人(显示)\n");

$smtp->datasend("Subject: $subject\n");

$smtp->datasend("To: $to\n");

$smtp->datasend("$filename_1\n\n");

while (read(FILE, $buf, 60*57)) {

$line=encode_base64($buf);

$smtp->datasend("$line");

}

$smtp->dataend();

$smtp->quit;

叶子博客上的自动发报告邮件的脚本实例

[root]# more /root/tools/mailmessage.pl

#!/usr/bin/perl

use Net::SMTP;

use MIME::Base64;

$filename_1 = `/bin/cat /root/tools/analog_report_log`;

chop($filename_1);

$filename_2 = `/bin/cat /root/tools/BlackIP_info`;

chop($filename_2);

$Day = `date --date="1 day ago" +%x`;

$boundary = "9876543210";

$user = $ENV{USER};

$from = $ENV{HOSTNAME};

$to = "XteamAdminGroup";

####################################################################

$mime='MIME-Version: 1.0

Content-Type: multipart/mixed; boundary='.$boundary.'

Content-Transfer-Encoding: 8bit
--'.$boundary.'

Content-Type: application/octet-stream; name="'.$filename1.'"

Content-Transfer-Encoding: base64

Content-Description: '.$filename.'

Content-Disposition: attachment; filename="'.$filename1.'"
';
#open(FILE, "<$filename") or die "$!";
$smtp = Net::SMTP->new('192.168.7.25');

$smtp->mail('perl-mail@joypark.com.cn');

$smtp->to('yp@mail.21dnn.com','yep@mail.21dnn.com','mengxd@mail.21dnn.com','lin@mail.21dnn.com','zhuh@mail.21dnn.com');

$smtp->data();

$smtp->datasend("From: xteam管理员\n");

$smtp->datasend("Subject: $Day 千龙邮箱用户使用情况报告 \n");

$smtp->datasend("To: $to\n");

$smtp->datasend("千龙邮箱用户使用情况分析:\n");

$smtp->datasend("$filename_1\n\n");

$smtp->datasend("昨日新添加的IP黑名单:\n");

$smtp->datasend("$filename_2");
while (read(FILE, $buf, 60*57)) {

$line=encode_base64($buf);

$smtp->datasend("$line");

}
$smtp->dataend();

$smtp->quit;
close (FILE);
system "cat /root/tools/analog_report_log >> /root/tools/analog_report_oldlog";
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: