Simple local test on smtp protocol with Net:SMTP (send test email)
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 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