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"; |
相关文章推荐
- linux通过shell脚本发送网络邮件
- PHP 命令行模式实战之cli+mysql 模拟队列批量发送邮件(在Linux环境下PHP 异步执行脚本发送事件通知消息实际案例)
- 浅析linux下如何用脚本自动发送文本mail邮件
- 利用linux mutt 发送邮件(在Shell脚本中使用比较方便)
- linux脚本实现自动发送和收取邮件的设置方法
- Linux使用shell脚本调用sendmail发送带附件的邮件
- linux脚本实现自动发送和收取邮件的设置方法
- linux发送邮件的shell脚本
- 浅析linux下如何用脚本自动发送文本mail邮件
- linux 编写监测脚本,如果停掉自动执行重启操作,并且发送邮件通知
- 利用linux mutt 发送邮件(在Shell脚本中使用比较方便)
- 一个在Linux上用sendmail发送带附件的邮件的脚本
- linux脚本发送邮件 shell发送邮件(使用 msmtp+mutt+shell来实现)
- linux发送邮件脚本
- Linux下shell脚本PING命令只要延迟高于100ms就发送个邮件
- linux提取系统信息发送邮件脚本
- linux系统CPU内存磁盘监控发送邮件脚本之二
- Linux下发送邮件命令:mutt 和 mail 以及 脚本
- Linux学习-->如何通过Shell脚本实现发送邮件通知功能?
- linux 定时执行shell脚本 【并发送信息到指定邮件centos6需要yum install sendmail】