Configure rsyslog to send email using a non-standard SMTP port


I run a couple of extremely lightweight servers at home. My provider blocks SMTP port 25 though, so it's difficult to get email notifications from them. Fortunately my email provider allows me to use port 26, so I just had to make a simple configuration change to the rsyslog.conf file to get ommail to work correctly

References

 

Purpose & Problem

I like to know when someone logs into my systems via SSH or SFTP/SCP. To that end I had been using a script that looks like this on some of my servers 'out there' on the internet:

$ModLoad ommail
$ActionMailSMTPServer smtp.server.tld
$ActionMailFrom loginalert@domain.tld
$ActionMailTo myalertemailinbox@anotherdomain.tld
$template mailSubject,"User logged into %hostname%"
$template mailBody,"RSYSLOG Alert\r %msg% at %timereported%"
$ActionMailSubject mailSubject
$ActionExecOnlyOnceEveryInterval 60
if $msg contains 'Accepted password for' then :ommail:;mailBody

This assumes an SMTP port of 25, which doesn't work if my servers are behind an ISP that doesn't open that port.

 

Solution

I wasn't able to find anything on google for a long time no matter how often I searched for "rsyslog ommail change port" or "ommail different smtp port" or "change smtp port rsyslog ommail uses". Eventually I stumbled across a forum post and then across information on the rsyslog.com website which lead me to a solution. I had to add this line to what I had:

$ActionMailSMTPPort 26

 

Taken together, the entire directive that I added to my /etc/rsyslog.conf file looks like this:

$ModLoad ommail
$ActionMailSMTPServer smtp.server.tld
$ActionMailSMTPPort 26
$ActionMailFrom loginalert@domain.tld
$ActionMailTo myalertemailinbox@anotherdomain.tld
$template mailSubject,"User logged into %hostname%"
$template mailBody,"RSYSLOG Alert\r %msg% at %timereported%"
$ActionMailSubject mailSubject
$ActionExecOnlyOnceEveryInterval 60
if $msg contains 'Accepted password for' then :ommail:;mailBody