Dynamically using mail host

Hi,

Can we dynamically using mail host to send mail in UNIX script if it is not configured on UNIX box?

Thanks,

Paventhan

I really don't understand the question.

You have a UNIX box.
The UNIX box is NOT configured to send or receive mail.
You want to send mail from the UNIX box.

What does 'dynamically' mean here?

Both sendmail and postfix have "null client" configurations, where they do not run as a service, but will connect to an external mail relay host.

Additionally, programs and libraries exist (PHP, Perl, Python) to connect to a Mail server via SMTP.

My UNIX box is not configured to send or receive mail using UNIX commands(sendmail or mailx). Now i call PERL mail module(which contains the mail host info) to send mails from unix script.

Can we define the mail host details in the UNIX script itself so it can use during every execution?

You can with the Net::SMTP module. Net::SMTP - search.cpan.org

You can set up the unix server by editing /etc/sendmail.cf (or similar) and finding the DS section. Un-comment the line to make it like the following:-

DSmyrelay.mycompany.com

This should be a mail router and should allow you to send stuff normally from any sendmail/mail/mailx command variation. You will also need to check that you can talk to the server on port 25 (smtp) Try the following:-

telnet myrelay.mycompany.com 25

You should get a connected message and wait on input. Typing quit should get you out. If you attempt pauses then times out after 30 seconds, there is a firewall blocking you or a routing problem. If it refuses you straight away, then it is not a mail relay.

I hope that this helps.

Robin
Liverpool/Blackburn
UK

Currently i am using simple perl script with Mail::Sendmail module as a separate file and the mail host ip is hardcoded in the perl script. I just call this perl script where i need to trigger mail.

I want to know do we have any way to define the mail host in the shell script itself. So it can be used during every exceution to send mail.

According to the CPAN documentation:

So just modify Sendmail.pm with the default SMTP server. You'll see lines looking like this:

%mailcfg = (
    # List of SMTP servers:
    'smtp'    => [ qw( localhost ) ],
    #'smtp'    => [ qw( mail.mydomain.com ) ], # example

Simply change localhost to your network's mail/hub.