linux 发送邮件脚本

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";
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值