Hi guys,
I'm attempting to use the Net::SMTP module in order to send emails from a server that i'm remotely logging into.
Please see the basic code I've set up below. I am attempting to get this working first before fleshing out the actual script.
#!/usr/bin/perl
use Net::SMTP;
use strict;
use warnings;
print "Content-type: text/html\n\n";
#print "test";
my $MailHost = "smtp.server.com";
my $MailFrom = "from\@address.com";
my $MailTo = "gilesy\@address.com";
my $subject = "Hello Gilesy";
my $MailBody = "This is the mail body";
#confirm connection with smtp server
my $smtp_test = Net::SMTP->new('smtp.server.com',
Timeout => 30,
Debug => 1,)|| print "ERROR creating SMTP obj: $! \n";
print "SMTP obj created.";
my $smtp = Net::SMTP->new($MailHost);
# Send the From and Recipient for the mail servers that require it
$smtp->mail($MailHost);
$smtp->to($MailTo);
# Start the mail
$smtp->data();
# Send the header.
$smtp->datasend("To: $MailTo\n");
$smtp->datasend("From: $MailFrom\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("\n");
# Send the message
$smtp->datasend("$MailBody\n\n");
# Send the termination string
$smtp->dataend();
$smtp->quit;
When I run this, I get the following output:
Net::SMTP>>> Net::SMTP(2.31)
Net::SMTP>>> Net::Cmd(2.29)
Net::SMTP>>> Exporter(5.64_01)
Net::SMTP>>> IO::Socket::INET(1.31)
Net::SMTP>>> IO::Socket(1.31)
Net::SMTP>>> IO::Handle(1.28)
Net::SMTP=GLOB(0xXXXXXXX)<<< 220 smtp.server.com Microsoft ESMTP MAIL
+Service ready at Mon, 12 Nov 2012 09:56:34 +0000
Net::SMTP=GLOB(0xXXXXXXX)>>> EHLO localhost.localdomain
Net::SMTP=GLOB(0xXXXXXXX)<<< 250-smtp.server.com Hello [12.34.56.78]
Net::SMTP=GLOB(0xXXXXXXX)<<< 250-SIZE
Net::SMTP=GLOB(0xXXXXXXX)<<< 250-PIPELINING
Net::SMTP=GLOB(0xXXXXXXX)<<< 250-DSN
Net::SMTP=GLOB(0xXXXXXXX)<<< 250-ENHANCEDSTATUSCODES
Net::SMTP=GLOB(0xXXXXXXX)<<< 250-STARTTLS
Net::SMTP=GLOB(0xXXXXXXX)<<< 250-X-ANONYMOUSTLS
Net::SMTP=GLOB(0xXXXXXXX)<<< 250-AUTH NTLM
Net::SMTP=GLOB(0xXXXXXXX)<<< 250-X-EXPS GSSAPI NTLM
Net::SMTP=GLOB(0xXXXXXXX)<<< 250-8BITMIME
Net::SMTP=GLOB(0xXXXXXXX)<<< 250-BINARYMIME
Net::SMTP=GLOB(0xXXXXXXX)<<< 250-CHUNKING
Net::SMTP=GLOB(0xXXXXXXX)<<< 250-XEXCH50
Net::SMTP=GLOB(0xXXXXXXX)<<< 250 XRDST
SMTP obj created.
From what I can see, there are no errors here. However, when I run this, I do not get any emails. This could be to do with server security but I guess I want to rule out that my code is the issue.
So could anyone confirm if my code is ok? If so, would you have any suggestions as to what might be causing the issue?