Mail notifications not working

Hi,
It seems GCP is blocking mail sent via mailx. Is it possible to configure icinga to send mail notifications via external SMTP server?

my /var/log/mail.log file have a lot of messages like this:

Jan  3 08:52:01 monitor sm-mta[24812]: 0BTHL6MC031190: to=servers@mydomain.com, delay=4+02:20:01, xdelay=00:10:55, mailer=esmtp, pri=26580000, relay=aspmx3.googlemail.com. [74.125.137.27], dsn=4.0.0, stat=Deferred: Connection timed out with aspmx3.googlemail.com.
Jan  3 09:02:01 monitor sm-mta[26970]: 101Hp6MC012549: to=servers@mydomain.com, delay=1+02:00:00, xdelay=00:10:55, mailer=esmtp, pri=7050000, relay=aspmx3.googlemail.com. [74.125.137.26], dsn=4.0.0, stat=Deferred: Connection timed out with aspmx3.googlemail.com.

From some research about this, I created a file /root/.mailrc with the content below:

set smtp-use-starttls
set ssl-verify=ignore
set smtp=smtp://smtp.gmail.com:587
set smtp-auth=login
set smtp-auth-user=servers@mydomain.com
set smtp-auth-password=MY*PASS
set from="Icinga Monitor <no-reply@mydomain.com>"

installed s-nail and adjust the line in file /etc/icinga2/scripts/mail-service-notification.sh

MAILBIN="s-nail"

but mail notifications still don’t work.
Any help would be appreciated

Icinga sends emails via whatever MTA you have configured on the machine.

Try something like sSMTP as a dumb relay to send via an external server which
Google likes (but good luck with that - Google is getting pretty unfriendly
about accepting email these days).

Antony.

Or to put it more simply:
Icinga runs only a external script for notification. What the script is doing, is up to you. If you install icinga, the setup routine copy two scripts into /etc/icinga2/scripts. You can use these one or you write your own script, use an other program or whatever.
We for example are using our own python script.

Hello @ronanlucio,
You can use mailx to send by smtp. Use the switch “-S smtp=“mysmtpserver””. I am able to send notification through the company (internal) smtp server this way

I hope this helps.
Alex

Hi @aclark6996, good one.
Do you mean adding it into /etc/icinga2/scripts?

MAILBIN="mail -S smtp=\"smtp.gmail.com\""

something like this?

Thank you @stevie-sy, sounds good

1 Like

No, keep the MAILBIN variable the same. Add the -S switch at the bottom of the standard Icinga notification scripts (/etc/icinga2/scrips/mail-host-notification.sh). You will need to edit it for your Linux version.

/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | $MAILBIN -r "$MAILFROM" -s "$SUBJECT" -S smtp="smtp.gmail.com" $USEREMAIL

Regards
A

Hi, thank you all for your helpful ideas.

What solved my issue in a fancy and fast way was Antony’s suggestion for installing an MTA to send messages using a third-party SMTP server.

Thanks