文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>用perl发送邮件

用perl发送邮件

时间:2010-10-13  来源:James_Guan

#!/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 "[email protected]"


相关阅读 更多 +
排行榜 更多 +
战术任务

战术任务

飞行射击 下载
愤怒的兽人战争安卓版

愤怒的兽人战争安卓版

冒险解谜 下载
粉碎射手跑安卓版

粉碎射手跑安卓版

冒险解谜 下载