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?

In reply to Net::SMTP Module query by gilesy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.