#!/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; #### 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.