#!/usr/bin/perl -w
# http://perldoc.perl.org/Net/SMTP.html
# http://search.cpan.org/~apleiner/Net-SMTP_auth-0.08/SMTP_auth.pm
use strict;
use threads;
use Net::SMTP_auth;
my $emlPath="@EML_PATH_VAR@";
my $smtpSvrIP = "@SMTP_SVR_IP_VAR@";
my $LocalBindIP = "@LOCAL_BIND_IP_VAR@";
my $heloDomain="@HELO_DOMAIN_VAR@";
my $authUsername="@AUTH_USERNAME_VAR@";
my $authPassword="@AUTH_PASSWORD_VAR@";
my $mailFrom = "@MAIL_FROM_VAR@";
my $rcptTo1 = "@RCPT_TO_VAR@";
my $needRetry = 0;
sub getDateTime
{
my $tTime = shift || time();
my ($second, $minute, $hour, $monthday, $month, $year, $weekday, $yearday, $isdst) = localtime($tTime);
$month++;
$second = ($second < 10) ? "0$second" : $second;
$minute = ($minute < 10) ? "0$minute" : $minute;
$hour = ($hour < 10) ? "0$hour" : $hour;
$monthday = ($monthday < 10) ? "0$monthday" : $monthday;
$month = ($month < 10) ? "0$month" : $month;
$year += 1900;
return "$year-$month-$monthday $hour:$minute:$second";
}
sub printResult
{
#my ($args) = @_;
my ($beginTime, $strCmd, $smtpConnector) = @_;
#my $smtpConnector = shift;
my $nowTime = &getDateTime();
my $spendTime = time - $beginTime;
my $retCode = $smtpConnector->code();
my $retMessage = $smtpConnector->message();
if ( $needRetry == 0 && $retCode > 400 && $retCode < 500 )
{
$needRetry = 1;
print "[$nowTime] cmd:$strCmd,from:$mailFrom,to:$rcptTo1,server:$smtpSvrIP,path:$emlPath,respond:$retCode $retMessage,spend:$spendTime, will retry\n";
return;
}
if ( $strCmd eq "DATA" )
{
my $newLinePos = index($retMessage, "\n");
$retMessage = substr($retMessage, $newLinePos + 1);
}
chop $retMessage;
print "[$nowTime] cmd:$strCmd,from:$mailFrom,to:$rcptTo1,server:$smtpSvrIP,path:$emlPath,respond:$retCode $retMessage,spend:$spendTime\n";
}
sub smtpSendSingleEML
{
open(EMLFILE, $emlPath) || die "Cannot open eml file: $emlPath($!)";
my $beginTime = time;
my $smtpConnector = Net::SMTP_auth->new($smtpSvrIP, Port => 25, Hello => $heloDomain, Timeout => 60, LocalAddr => $LocalBindIP, Debug => 0);
if ( defined($smtpConnector) )
{
if ( $authUsername ne "" )
{
if ( ! ($smtpConnector->auth('LOGIN', $authUsername, $authPassword)) )
{
printResult($beginTime, "AUTH", $smtpConnector);
return 0;
}
}
if ( ! ($smtpConnector->mail($mailFrom)) )
{
printResult($beginTime, "MAIL", $smtpConnector);
return 0;
}
if ( ! ($smtpConnector->to($rcptTo1)) )
{
printResult($beginTime, "RCPT", $smtpConnector);
return 0;
}
if ( ! ($smtpConnector->data()) )
{
printResult($beginTime, "DATABEGIN", $smtpConnector);
return 0;
}
while( <EMLFILE> )
{
chop $_;
$smtpConnector->datasend("$_\n");
}
$smtpConnector->dataend();
printResult($beginTime, "DATA", $smtpConnector);
$smtpConnector->quit();
}
else
{
my $nowTime = &getDateTime();
my $spendTime = time - $beginTime;
print "[$nowTime] cmd:HELO,from:$mailFrom,to:$rcptTo1,server:$smtpSvrIP,path:$emlPath,respond:550 Connect to server fail,spend:$spendTime\n";
}
close(EMLFILE);
}
=comment
sub smtpSendByFolder
{
my $sendEmlCnt = 0;
chdir($emlDir) || die "Cannot chdir to $emlDir: ($!)";
for( my $i = 1; $i <= $cycleCnt; $i++ )
{
while( glob("*.eml") )
{
$sendEmlCnt++;
$emlPath = "$emlDir/$_";
smtpSendSingleEML();
}
}
}
$SIG{'PIPE'} = 'IGNORE';
my @threadpool;
for( my $i = 1; $i <= $threadCnt; $i++ )
{
my $thread = threads->create(\&smtpSendByFolder, "Thread: $i");
push(@threadpool, \$thread);
}
foreach my $thread (@threadpool)
{
$$thread->join();
}
=cut
smtpSendSingleEML();
if ( $needRetry == 1 )
{
sleep 60;
smtpSendSingleEML();
}
几点说明:
1,发送邮件前,需要替换文件头的 "@SMTP_SVR_IP_VAR@" 等变量
2,可自动识别是否需要认证,即可连接smtp服务器或mx服务器发信
3,安装perl后默认安装Net::SMTP模块,但没有安装Net::SMTP_auth模块,需要另外安装
4,Net::SMTP_auth要用到Digest::HMAC_MD5和Authen::SASL,需要另外安装
5,所有perl模块都可以在http://search.cpan.org找到下载,下载后解开安装包,执行perl Makefile.pl && make && make install可完成安装,或将*.pm拷贝到/usr/lib/perl5/5.8.8相应的目录下完成安装
6,查看系统已经安装的perl模块的方法:find /usr/lib/perl5/5.8.8 | grep .pm
分享到:
相关推荐
在 Docker 容器上构建 mod_auth_openidc rpm要求如何构建rpm 在 Docker 主机服务器上克隆这个项目 $ git clone https://github.com/wadahiro/mod_auth_openidc_rpmbuild_container.git 构建泊坞窗图像 $ cd mod_auth...
官方离线安装包,测试可用。请使用rpm -ivh [rpm完整包名] 进行安装
1.SQL Server使用windows用户连接数据库报错 Caused by: java.lang.UnsatisfiedLinkError: no sqljdbc_auth in java.library.path 2.因为缺少sqljdbc_auth.dll 文件 3.下载此资源放到jdk安装路径bin目录下,解决此...
Git空间Visualize your GitHub Profile 一个 Web 应用程序 :magnifying_glass_tilted_right: 可视化 GitHub 配置文件 :bar_chart: 使用简单的身份验证 :locked_with_key: 使用react-auth0 :card_file_box: 技术栈 :...
sqljdbc_auth.dll 支持64位,在Java程序使用SSL加密方式连接到sqlserver时非常有用。
您需要有一个(免费的)mailgun 帐户才能发送欢迎电子邮件。 您需要知道您的 mailgun 域和 HTTP API 密钥。 跑步 克隆存储库并切换到它的目录 安装依赖: mix deps.get && npm install 创建和迁移数据库(在尝试...
mod_auth_mysql-3.0.0.tar.gz
ion_auth ion_auth数据库代码
firebase_auth_oauth Flutter插件,可轻松使用FirebaseAuth执行OAuth... firebase_auth: ^1.0.0 firebase_core: ^1.0.0 firebase_auth_oauth: ^1.0.1 然后在您的项目中只需调用 FirebaseUser user = await Fireba
资源来自pypi官网。 资源全名:django_openstack_auth-1.2.0.tar.gz
资源分类:Python库 所属语言:Python 资源全名:google_auth-1.12.0-py2.py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源来自pypi官网。 资源全名:two_factor_auth_olaii-1.1.tar.gz
$ rails g apple_auth:config这将生成一个新的初始化程序: apple_auth.rb具有以下默认配置: AppleAuth . configure do | config | # config.apple_client_id = <Your client_id in your Apple Developer ...
:high_voltage: 开/关可用于捐赠 :high_voltage: 填写详细信息以联系Procurer :star: 推荐依据: :star: 我使用了什么技术: :high_voltage: React-Native :high_voltage: Firebase Auth + Firebase实时数据库 :...
五、 pg_auth_members: pg_auth_members: pg_auth_members: pg_auth_members:pg_auth_members: pg_auth_members:pg_auth_members:pg_auth_members:pg_auth_members: .64 七、 pg_tablespace: pg_tablespace: pg_...
python库。 资源全名:pymongo_smart_auth-1.2.0.tar.gz
python库。 资源全名:django_openstack_auth-1.0.2.tar.gz
python库。 资源全名:dffml_feature_auth-0.0.3.tar.gz
资源来自pypi官网,解压后可用。 资源全名:django_openstack_auth-1.3.0-py2-none-any.whl
资源来自pypi官网。 资源全名:asymmetric_jwt_auth-0.4.1.tar.gz