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