[Scottish] Send mail from script via remote smtp

Michael Maclean michael at no-surprises.co.uk
Fri Apr 25 10:18:56 BST 2008


Hi,

Paxton, Darren wrote:
> Now for what is probably the bleeding obvious bit. Our standard build
> has sendmail disabled by default so what I'd like to do it be able to
> tell the mail command to connect to our internal smtp server in order to
> deliver the message to the needed recipients.

I've done something very similar in the past to let me know if a mail 
server isn't running on reboot - obviously if it's not running I can't 
send the email in the normal way ;) I used a Perl script along the lines of:

#!/usr/bin/perl -w

use strict;
use Net::SMTP;

my $smtp = Net::SMTP->new("mailserver.example.com");

$smtp->mail("sender\@example.com");
$smtp->recipient("recipient\@example.com",);

$smtp->data;

$smtp->datasend("From: sender\@example.com\n");
$smtp->datasend("To: recipient\@example.com\n");
$smtp->datasend("Subject: Permissions problem in /tmp\n");
$smtp->datasend("\n");

$smtp->datasend("Please fix permissions on /tmp.");

$smtp->dataend;
$smtp->quit;

Hope this helps.

Michael





More information about the Scottish mailing list