Skip to content

Instantly share code, notes, and snippets.

@zxteloiv
Last active December 14, 2015 08:18
Show Gist options
  • Save zxteloiv/5056992 to your computer and use it in GitHub Desktop.
Save zxteloiv/5056992 to your computer and use it in GitHub Desktop.
sending mail using perl, with auth
#!/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