#!/usr/local/bin/perl -w
##基于SMTP的邮件发送程序##
use Net::SMTP_auth;
#get'the smtp server host.
print "please enter the SMTP server host!\n";
$mailhost=<>;
chomp ($mailhost);
#$mailhost= substr ($mailhost,1); #delete the "." in the front of $usernamein.
print $mailhost."\n\n";
#connect with SMTP server
$smtp = Net::SMTP_auth->new($mailhost) || die "Can't connect to SMTP Server";
print "The SMTP server is:".$smtp->banner()."\n";
#get'the username and password.
print "Please enter your Email username:\n";
$username=<>;
chomp($username);
print "Your Email username is : ".$username."\n\n";
print "Please enter your Email password:\n";
$passwd=<>;
chomp($passwd);
print "Your Email password is : ".$passwd."\n\n";
#generate your source address.
$saddress=$username."\@" ;
$saddress.=substr($mailhost,5);
$saddress=~s/@/\@/g;#regex expression, for example : xiaoping4220\@163.com.
print "Your Email address is : ".$saddress."\n\n";
#authentication
$num=$smtp->auth ('LOGIN',$username,$passwd);
#if ($num!=1)
#{
# print "authenticate failed!\n";
# exit;
#}
#else
#{
# print "authenticate sucessful!\n";
#}
#get'the destination address.
print "please enter the email destination address:\n";
$destaddress=<>;
chomp ($destaddress);
$destaddress=~s/@/\@/g; #regex expression, for example : xiaoping4220\@163.com.
print "The destination Email Address is : ".$destaddress."\n\n";
$smtp->mail($saddress);
$smtp->to($destaddress);
#mail data department.
$smtp->data();
$smtp->datasend("From: $saddress \n");
$smtp->datasend("To: $destaddress \n");
$smtp->datasend("Subject: perl mail test\n");
$smtp->datasend("\n");
$smtp->datasend("This is xiaoping's test email \n");
$smtp->datasend("Have a good day!\n");
$smtp->dataend();
$smtp->quit;
print "The mail has been sent successful!";
exit 0;
|