Chinaunix首页 | 论坛 | 博客
  • 博客访问: 482556
  • 博文数量: 67
  • 博客积分: 2952
  • 博客等级: 少校
  • 技术积分: 679
  • 用 户 组: 普通用户
  • 注册时间: 2006-01-24 10:50
文章分类

全部博文(67)

文章存档

2011年(9)

2010年(36)

2009年(8)

2008年(5)

2007年(5)

2006年(4)

我的朋友

分类:

2010-10-13 10:02:45

#!/usr/bin/perl


use MIME::Lite;


push(@body, "Failed: Server = $IP Stratum = $stratum\n");

# Set up email
        $to = "jamesg\@sz.webex.com";
        $from = "ntpchk\@sz.webex.com";
        $subject = "NTP server problem";
        $message = join("\n",@body);


        # Send email
        email($to, $from, $subject, $message);

        # Email function
        sub email
        {
        # Get incoming parameters
         local ($to, $from, $subject, $message) = @_;

        # Create a new message
        $msg = MIME::Lite->new(
        From => $from,
        To => $to,
        Subject => $subject,
        Data => $message
        );

        # Send the email
        MIME::Lite->send('smtp', '10.224.106.10', Timeout => 60);
        $msg->send();
        }


MIME::Lite只能发送纯文本的邮件,如果要发送带有HTML格式的邮件,就必须用到MIME::Lite::HTML模块啦。

#!/usr/bin/perl


use MIME::Lite::HTML;

        $to = "jamesg\@sz.webex.com";
        $from = "ntpchk\@sz.webex.com";
        $subject = "NTP server problem";

        # Send email
        email($to, $from, $subject, $message);

        # Email function
        sub email
        {
        # Get incoming parameters
         local ($to, $from, $subject, $message) = @_;

        # Create a new message
        $msg = MIME::Lite::HTML->new(
        From => $from,
        To => $to,
        Subject => $subject,
        );

        my $MIMEmail = $msg->parse("file://tmp/test.html");
        # Send the email
        $MIMEmail->send('smtp', '10.224.106.10', Timeout => 60);
        }


其实用bash command更简单

cat /tmp/sysinfochk.log |/usr/bin/formail -I "MIMIE-Version:1.0" -I "Content-type:text/html" -I "Subject:sjimage:SDE_DB:SYSINFO check log"|/usr/sbin/sendmail -oi "jamesg@sz.webex.com"


阅读(919) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~