- To: "Carlo Sogono" <csogono@xxxxxxxxxxxxx>
- Subject: RE: [SLUG] Monitoring postfix/sendmail
- From: james@xxxxxxxxxxxxxxxxxxxx
- Date: Tue, 2 Aug 2005 15:19:06 +1000 (EST)
- Cc: SLUG <slug@xxxxxxxxxxx>, james@xxxxxxxxxxxxxxxxxxxx
- User-agent: SquirrelMail/1.4.4
>> Does the mail need to reach you on that machine, or on a remote
>> one? If it only needs to be able to send mails you could use either
>> something like Nullmailer, or a Perl or Python script to talk SMTP
>> to the target mailhost.
>
> It's to be sent to the email add of our 'monitoring employee'.
But is this address on the machine being monitored, or a different one?
> I use
> Perl to talk to "/usr/sbin/sendmail -t" like so:
<snip>
> I assue I could do the same thing if I opened a network socket to the
> smtp server and printed raw smtp commands?
Should do. I tested my understanding of the RFC by telnetting to port 25 and sending
mails that way; it lives quite pleasingly up to the "Simple" part of its name.
> I've already finished this
> script that uses sendmail and I'll test your suggestion. I'm currently
> rummaging through Perl sites and I need a quick answer on how to use
> this on a socket. I've never done socket programming on Perl before...
You could also try the MIME::Lite module, which is serving nicely at a certain large
financial institution. The following script should hopefully be a useful example.
We're using it to mail an encrypted file as an attachment, so you probably won't
need the whole subroutine:
my $mailhost = "mailhost.example.com"
sub mail {
my ($attachment, $subject, $to_address, $from_address) = @_;
unless($attachment && $subject && $to_address && $from_address) {
die("Need a file to attach, a subject line, a To: address and a
From: address!\n");
}
my $message_body = "\n";
# Create the initial text of the message
my $mime_msg = MIME::Lite->new(
From => $from_address,
To => $to_address,
Subject => $subject,
Type => 'multipart/mixed',
Encoding => 'binary'
) or die "Error creating MIME body: $!\n";
# Attach the file
if($body) {
$mime_msg->attach(
Type => 'TEXT',
Data => $body
) or die "Error inserting message body: $!\n";
}
$mime_msg->attach(
Type => 'application/data',
Path => $attachment,
Disposition => 'attachment',
Encoding => 'base64',
ReadNow => 'true'
) or die "Error attaching file $attachment: $!\n";
MIME::Lite->send('smtp', "$mailhost", Timeout=>60);
$mime_msg->send;
return 0;
}
# mail the encrypted file
mail("$attachment.pgp", $subject_line, $to_address, $from_address);