I have been scratching my head trying to figure out how to send an email from Perl on Windows 7. I am unable to install any Perl modules other than what comes default with the Active Perl install. (That means Mime::Lite, Email::Sender, and Mail::Sendmail are all off the table)
The only email sending module I can find appears to be Net::SMTP, but I have been unable to figure out how to use it correctly. I am not very familiar with what an SMTP server is, let alone how they work. Every other post I have found about sending emails suggests using different modules which I don't have.
I saw another post suggesting to use Net::SMTP::SSL to connect to gmail but I do not have the SSL module.
This is some code I have so far, I am attempting to use gmail as my SMTP server:
use Net::SMTP;
$smtp = Net::SMTP->new('smtp.gmail.com'); # connect to an SMTP server
$smtp->mail('fromAddress@gmail.com'); # use the sender's address here
$smtp->to('toAddress@test.com'); # recipient's address
$smtp->data(); # Start the mail
# Send the header.
$smtp->datasend("To: toAddress\@test.com\n");
$smtp->datasend("From: myAddress\@gmail.com\n");
$smtp->datasend("Subject: Test email\n");
$smtp->datasend("\n");
# Send the body.
$smtp->datasend("Hello, World!\n");
$smtp->dataend(); # Finish sending the mail
$smtp->quit; # Close the SMTP connection
I keep getting the error:
Can't call method 'mail' on an undefined value
which I'm assuming means that it is failing to connect to the SMTP server. How can I fix this?
Also are there any other modules that come standard with Active Perl that are easier to use?
I was really looking for something similar to the Linux SENDMAIL command that is super simple and doesn't even require you to connect or authenticate anything. The Linux SENDMAIL command seems to even allow you to make up any "from" address you want which is probably really dangerous but awesome!
EDIT
Also it is not a requirement that I go through gmail. It was just the first thing i thought of.