[CentOS] Sending mail from CLI to another SMTP host

Thu Apr 1 13:07:02 UTC 2010
Les Mikesell <lesmikesell at gmail.com>

Fajar Priyanto wrote:
> Hi all,
> Is it possible to send mail from CLI (bash, python) without any LOCAL
> SMTP installed, using SMTP on another machine.
> Care to give a glimpse of the code?
> Thank you.

Personally, I'd use the default Centos install of sendmail because it's there, 
it's easy, and it works the way mail has been intended to work for decades.  The 
default setup is to accept only from localhost, but send anywhere. If you want 
to relay through a known host, configure SMART_HOST in /etc/mail/sendmail.mc and 
restart the sendmail service.  Then your scripts and other programs can simply 
run sendmail to queue/delivey instead of doing it themselves, and can deliver to 
local recipients as well as remote.

If you really don't want a mailer and are ok with failures or want to handle 
queuing and retries yourself, the epel repo has perl-Mail-Sender which is a 
fairly complete smtp send-only client.  After installing use perldoc or 'man 
Mail::Sender' to see the documentation.

-- 
   Les Mikesell
    lesmikesell at gmail.com