Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.