I had some trouble getting net:SMTP working on a server that required smtp authentication on a windows web server using cgi perl.
We finally got it working, so I wanted to share the code somewhere:
Code: PERL
#!C:\perl\bin\perl
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use Net::SMTP;
use MIME::Base64;
print header;
print start_html("Environment");
#Keep debug off in order for web and email to both work correctly on large messages
$smtp = Net::SMTP->new(
'[B]smtp.MYEMAILSMTPSERVER.com[/B]' ,
# may need a helo parameter here on some servers
Timeout => 30,
Debug => 0,
);
$smtp->datasend("AUTH LOGIN\n");
$smtp->response();
# -- Enter sending email box address username below. We will use this to login to SMTP --
$smtp->datasend(encode_base64('[B]TYPEEMAILACCOUNTUSERNAMEHERE[/B]') );
$smtp->response();
# -- Enter email box address password below. We will use this to login to SMTP --
$smtp->datasend(encode_base64('[B]TYPEEMAILACCOUNTPASSWORDHERE[/B]') );
$smtp->response();
# -- Enter email FROM below. --
$smtp->mail('[B]ENTEREMAILADDRESSFROM@DOMAINNAME.COM[/B]');
# -- Enter email TO below --
$smtp->to('[B]ENTEREMAILADDRESSTOMAILTO@DOMAINNAME.COM[/B]');
$smtp->data();
#This part creates the SMTP headers you see
$smtp->datasend("To: [B]Test\@DOMAINNAME.com[/B]\n");
$smtp->datasend("From: A Test Account <[B]TEST\@DOMAINNAME.com[/B]>\n");
$smtp->datasend("Content-Type: text/html \n");
$smtp->datasend("Subject: A Test Message");
# line break to separate headers from message body
$smtp->datasend("\n");
$smtp->datasend("Here is my test message body");
$smtp->datasend("\n");
$smtp->dataend();
$smtp->quit;