Subject: Re: Simple mail sender?
To: Bruce Martin <brucem@cat.co.za>
From: Jeremy C. Reed <reed@reedmedia.net>
List: netbsd-help
Date: 11/16/2001 09:50:26
On Fri, 16 Nov 2001, Bruce Martin wrote:

> I am looking into adding simple functionality to a NetBSD system of ours.
> Under certain error conditions, I want the system to check if it has network
> access to a (SMTP?) mailer (i.e. is there some sort of config file on it to
> reach a mailer?), and then for it to generate a very simple text email, and
> send it to a fixed email address.
> 
> I just need a starting point - what should I look into to configure where
> the (SMTP?) mailserver is, and send the simple mail to it?

You want to find where a mailserver is -- you need to find the top
priority (lowest number) MX record. If no MX record exists, just use the A
record for the hostname. Use dig(1) with "mx" query. Then you can parse
this info to find the mailserver.

You want to check if you have network access to the mailserver -- then you
can use telnet(1), such as:

  (echo quit ; sleep 5) | telnet mail.host.here 25 2>&1 | egrep \
'Connection refused|Unknown host|Unable to connect|No address associated\
with hostname|Connection timed out' >/dev/null 2>&1 && echo problem

Then to send a mail to a fixed address, you could do echo the SMTP
commands and pipe through telnet to the mailserver you want to use.

There are many others way of doing it too.

   Jeremy C. Reed
   http://www.reedmedia.net/