加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Perl 发送邮件

发布时间:2020-12-15 23:45:03 所属栏目:大数据 来源:网络整理
导读:v-lhb-mgr01:/root/mon# cat m5.pl use Net::SMTP;# mail_user should be your_mail@163.comsub send_mail{ my $to_address = shift; my $mail_user = 'zhao.yangjian@163.com'; my $mail_pwd = 'xxxxxxxxxxxxxx'; my $mail_server = 'smtp.163.com'; my $fr
v-lhb-mgr01:/root/mon# cat m5.pl 
use Net::SMTP;

# mail_user should be your_mail@163.com
sub send_mail{
    my $to_address  = shift;
    my $mail_user   = 'zhao.yangjian@163.com';
    my $mail_pwd    = 'xxxxxxxxxxxxxx';
    my $mail_server = 'smtp.163.com';

    my $from    = "From: $mail_usern";
    my $subject = "Subject: here comes the subjectn";

    my $message = <<CONTENT; 
    **********************
    here comes the content
    **********************
CONTENT

    my $smtp = Net::SMTP->new($mail_server);

    $smtp->auth($mail_user,$mail_pwd) || die "Auth Error! $!";
    $smtp->mail($mail_user);
    $smtp->to($to_address);

    $smtp->data();             # begin the data
    $smtp->datasend($from);    # set user
    $smtp->datasend($subject); # set subject
    $smtp->datasend($message); # set content
    $smtp->dataend();

    $smtp->quit();
};

@arr_mail=( '267020090@qq.com','625613873@qq.com','13984480@qq.com','zhaoyangjian@zjcap.cn');
foreach (@arr_mail){
send_mail $_;
}; 

------------------------------------------------------------------------------------------------------------------------
需要安装Authen::SASL模块
v-lhb-mgr01:/root/mon# cpan Authen::SASL


CPAN is the world-wide archive of perl resources. It consists of about
300 sites that all replicate the same contents around the globe. Many
countries have at least one CPAN site already. The resources found on
CPAN are easily accessible with the CPAN.pm module. If you want to use
CPAN.pm,lots of things have to be configured. Fortunately,most of
them can be determined automatically. If you prefer the automatic
configuration,answer 'yes' below.

If you prefer to enter a dialog instead,you can answer 'no' to this
question and I'll let you configure in small steps one thing after the
other. (Note: you can revisit this dialog anytime later by typing 'o
conf init' at the cpan prompt.)
Would you like me to configure as much as possible automatically? [yes] yes

  /usr/bin/make install  -- OK

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读