Skip to content

Instantly share code, notes, and snippets.

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 ===
$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;
exit 1;
if( !$smtp->recipient( $to ) ) {
warn "SMTP refused RCPT TO: $to: ".$smtp->code." ".$smtp->message;
exit 2;
$smtp->datasend( $pre_data . $data );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment