Last active
December 14, 2015 08:18
-
-
Save zxteloiv/5056992 to your computer and use it in GitHub Desktop.
sending mail using perl, with auth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use Net::SMTP; | |
use Authen::SASL; | |
if(@ARGV < 2){ | |
die "usage: SendMail.pl <MailTo> <MimeFile>"; | |
} | |
my($MailTo, $MimeFile) = @ARGV; | |
my $smtp = Net::SMTP->new('111.222.3.123'); | |
my $line; | |
$smtp->auth('user','passwd') or die "authertication failed: $!\n"; | |
$smtp->mail("someone\@example.com"); | |
$smtp->to($MailTo); | |
open (IN, $MimeFile) or die "open $MimeFile fail"; | |
$smtp->data(); | |
$line = <IN>; | |
while($line) | |
{ | |
$smtp->datasend($line); | |
$line = <IN>; | |
} | |
close IN or die "can not close $MimeFile fail"; | |
$smtp->dataend(); | |
$smtp->quit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment