Skip to content

Instantly share code, notes, and snippets.

@eniocarboni
Created August 31, 2018 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eniocarboni/ea3747c6aa5be32a35f9accd96f23296 to your computer and use it in GitHub Desktop.
Save eniocarboni/ea3747c6aa5be32a35f9accd96f23296 to your computer and use it in GitHub Desktop.
Simple local test on smtp protocol with Net:SMTP (send test email)
#! /usr/bin/perl
use Net::SMTP;
use utf8;
# === Start of variables to modify ===
$from='<YOUR_FROM@YOUR_FROM_DOMAIN>';
$to ='<YOUR_RECIPIENT@YOUR_RECIPIENT_DOMAIN>';
$subject='test message with Net::SMTP';
$data='Test msg row 1
test msg row 2
...
test msg row n
';
# === End of changes ===
$pre_data="Subject: $subject\nTo: $to\n\n";
$smtp=Net::SMTP->new(Host=>'localhost', Debug=>1);
die "Unable to connect\n" unless $smtp;
print $smtp->banner();
if( !$smtp->mail($from) ) {
warn "SMTP refused MAIL FROM: $from: ".$smtp->code." ".$smtp->message;
$smtp->quit;
exit 1;
}
if( !$smtp->recipient( $to ) ) {
warn "SMTP refused RCPT TO: $to: ".$smtp->code." ".$smtp->message;
$smtp->quit;
exit 2;
}
utf8::encode($data);
$smtp->data();
$smtp->datasend( $pre_data . $data );
$smtp->dataend();
$smtp->quit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment