2

Is it possible to use the ommail module that comes with rsyslog to send email through a local postfix install. I use gmail as my smtp and ommail doesn't do authentication. Will using something like the following in an rsyslog .conf file work?

module(load="ommail")

template (name="mailBody"  type="string" string="RSYSLOG Alert\\r\\nmsg='%msg%'")
template (name="mailSubject" type="string" string="Emergency logged on %hostname%")

    if $msg contains "hard disk fatal failure" then {
       action(type="ommail" server="localhost" port="25"
              mailfrom="rsyslog@localhost"
              mailto="root"
              subject.template="mailSubject"
              action.execonlyonceeveryinterval="21600")
    }
steveH
  • 148
  • 2
  • 6

1 Answers1

0

The short answer - it's possible, yet postfix must be configured to use external mail service as local relay. Provided configuration above is incomplete and probably, postfix will fail to send email to a public email using external service as relay.

  • i'll skip postfix installation steps (google for any postfix install howto)
  • Configure postfix with your preferred mail service (i.e. Gmail). For this example, i'll use my region email service Inbox.LV.
#inbox: max 15 msg/h and 5msg/m
relayhost = [mail.inbox.lv]:465
#yahoo: cant get app password
#relayhost = [smtp.mail.yahoo.com]:465
# strict rate limiting
smtp_fallback_relay = [smtp.yandex.ru]:465

# Limit 15 emails per hour per email address
anvil_rate_time_unit = 3600s
smtpd_client_message_rate_limit = 15

smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_type = cyrus
smtp_sasl_mechanism_filter = login

default_process_limit = 5
smtpd_client_connection_count_limit = 2

##enable to be able to send email using different external relays
smtp_sender_dependent_authentication = yes
sender_dependent_relayhost_maps = hash:/etc/postfix/sasl/sender_relay
smtp_sasl_password_maps = hash:/etc/postfix/sasl/pass_maps
 - [main.cf included relays conf (run postconf on these files)][3]
 - restart postfix service
 - run to test that relay is working

`echo "This is a test email body." | mail -s "Subject" -a "From: service1@inbox.lv" any.destination@email.service`
  • Configure rsyslog to send email:
    • create file /etc/rsyslog.d/email.conf and restart rsyslog after editing it.
module(load="ommail")
    template (name="mailBody"  type="string" string="%timegenerated% %msg%")
    template (name="mailSubject" type="string" string="LTE problem <%syslogtag%>")



action(type="ommail" server="127.0.0.1" port="25"
                mailfrom="service1@inbox.lv"
                mailto=["service1@inbox.lv"]
                subject.template="mailSubject"
            body.enable="on"
            template="mailBody"
            queue.type="FixedArray"
            queue.filename="mailqueue"
            queue.saveOnShutdown="on"
            action.execOnlyOnceEveryInterval="60"
            action.resumeRetryCount="-1"
            action.reportSuspension="on"
            action.reportSuspensionContinuation="on"
            action.errorfile="/var/spool/rsyslog/ommailerror.log"
            action.resumeInterval="5"
            action.resumeIntervalMax="300"
        )

Please, note that ommail for body template uses other action attributes "template" and "body.enable".

Linux Armbian 21.05.6 Focal

rsyslog swVersion="8.2001.0"

Example o/p from mail.log:

Jan 16 15:42:44 orangepi3 postfix/pickup[310061]: B1E3D63CA9: uid=1000 from=<service1@inbox.lv>
Jan 16 15:42:44 orangepi3 postfix/cleanup[310871]: B1E3D63CA9: message-id=<20230116134244.B1E3D63CA9@opi3.colt.lan>
Jan 16 15:42:44 orangepi3 postfix/qmgr[266048]: B1E3D63CA9: from=<service1@inbox.lv>, size=352, nrcpt=1 (queue active)
Jan 16 15:42:48 orangepi3 postfix/smtp[310874]: B1E3D63CA9: to=<some@other.email>, relay=mail.inbox.lv[194.19.227.101]:465, delay=3.8, delays=0.03/0.05/3.5/0.24, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 4927F3E60F52)
Jan 16 15:42:48 orangepi3 postfix/qmgr[266048]: B1E3D63CA9: removed

diabolusss
  • 26
  • 3