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

perl 邮件发送示例详解

发布时间:2020-12-16 00:08:19 所属栏目:大数据 来源:网络整理
导读:一、使用 Mail::Sender模块 先申请一个163的邮箱; #!/usr/bin/perl use warnings; use strict; use Mail::Sender; ? my $sender = new Mail::Sender { ? smtp ? ?= 'smtp.163.com', ? from ? ?= 'your_mail@163.com",helvetica; line-height:18px"> ? auth ?
一、使用 Mail::Sender模块
先申请一个163的邮箱;

#!/usr/bin/perl
use warnings;
use strict;
use Mail::Sender;
?
my $sender = new Mail::Sender
{
? smtp ? ?=> 'smtp.163.com',
? from ? ?=> 'your_mail@163.com",helvetica; line-height:18px">? auth ? ?=> "LOGIN",helvetica; line-height:18px">? authid ?=> "yourmail",helvetica; line-height:18px">? authpwd => "your_mail_password"
} or die "error";
my $message = "hello,give you some message";
if($sender-> MailMsg ({
? ? ? ? ? ? ?to ? ? ?=> 'want_to@gmail.com',helvetica; line-height:18px">? ? ? ? ? ? ?subject => "test",helvetica; line-height:18px">? ? ? ? ? ? ?msg ? ? => ?$message,})<0)
? die "$Mail::Sender::Error/n";
}
$sender->Close();
二、使用Net::SMTP_auth
use strict; use Net::SMTP_auth;
?

&send_mail();
print "send mail overn";
# mail_user should be your_mail@163.com
sub send_mail{
? my $to_address ?= 'want_to@gmail.com';
? my $mail_user ? = 'your_mail@163.com';
? my $mail_pwd ? ?= 'your_mail_password';
? 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,helvetica; line-height:18px">? ? ? ? ? ? ? ? ? ? ? ? ? ? Timeout =>120,helvetica; line-height:18px">? ? ? ? ? ? ? ? ? ? ? ? ? ? Debug ? =>1) or die "ERROR! $!";
? $smtp->auth('LOGIN',$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();
}?

(编辑:李大同)

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

    推荐文章
      热点阅读