Skip to content

Instantly share code, notes, and snippets.

@jcdarwin
Last active August 15, 2024 08:08
Show Gist options
  • Save jcdarwin/fa9235dd48276f348cc7 to your computer and use it in GitHub Desktop.
Save jcdarwin/fa9235dd48276f348cc7 to your computer and use it in GitHub Desktop.
How to allow monit to use gmail as a smtp relay to send out alert emails
# visit https://accounts.google.com/DisplayUnlockCaptcha and click to allow access
# edit /etc/monit/monitrc to include the following
set mailserver smtp.gmail.com port 587
username "[email protected]" password "whatever"
using tlsv1
with timeout 30 seconds
# run the following to validate access
/etc/init.d/monit restart
monit validate
@alexandershahbazov
Copy link

Hello,
I have the same google mail server and it works. Name is without @gmail.com. Password is app password of 16 characters:
set mailserver smtp.gmail.com port 587
username "name" password "xxxxxxxxxxxxxxxx",
using tlsv1

set alert [email protected]

But yahoo mail server doesn't work in monit. name is with @yahoo.com, password also is app password of 16 characters:
set mailserver smtp.mail.yahoo.com port 587
username "[email protected]" password "xxxxxxxxxxxxxxxx",
using tlsv1

set alert [email protected]
Of course set alert to yahoo works if mail server is gmail but I need yahoo mail server in monitrc.
I tried various ways, but without success.
Maybe you have a working option with yahoo mail server for monit.
Thank you.

@geolaw
Copy link

geolaw commented Jan 11, 2021

+1 for the google "username" not needing the @gmail.com part - I just spent an hour on this trying to get it to work and that was the secret sauce
I still can't get my google apps full domain name to work, but my gmail will work for now

@MattiaCC93
Copy link

thanks @geolaw !!!

@annahri
Copy link

annahri commented Oct 11, 2022

tlsv1 is no longer working. Use tlsv13 instead

@geolaw
Copy link

geolaw commented Oct 11, 2022

@annahri -
centos 7 vm on linode - Do I need a special build of monit to support tlsv13?
I've got both openssl and openssl11 installed

[root@web3 etc]# monit -V
This is Monit version 5.30.0
Built with ssl, with ipv6, with compression, with pam and with large files
Copyright (C) 2001-2021 Tildeslash Ltd. All Rights Reserved.

[root@web3 etc]# monit reload
/etc/monitrc:8: Your SSL Library does not support TLS version 1.3 'TLSV13'
[root@web3 ~]# openssl version
OpenSSL 1.0.2k-fips 26 Jan 2017
[root@web3 etc]# openssl11 version
OpenSSL 1.1.1k FIPS 25 Mar 2021

I believe openssl11 supports 1.3

@trevmlt
Copy link

trevmlt commented Oct 11, 2022

I could not get tlsv1 to work, but using just tls worked like a charm (i.e. using tls)

@abbychette
Copy link

Hello, for few days , i've try to correct error in my Monit (V5.27-2) log (error : Mail: SSL connection error: error:141E70BF:SSL routines:tls_construct_client_hello:no protocols available)
When sending alert email to my gmail account. My monit email config is:
set mailserver smtp.gmail.com port 587
username xxxxxxxxxxxx password xxxxxxxxxxx
using tlsv1
with timeout 30 seconds
set alert [email protected]
I've tried with TLS, TLSV1, TLSV12 or TLSV13 without progress.
If someone got idea? Thanks

@2bj
Copy link

2bj commented Aug 15, 2024

I found this solution (aug 2024):
turn on 2fa on gmail acc, go to https://myaccount.google.com/apppasswords and create app password and use it for monit
here is my config:

set mailserver smtp.gmail.com port 587
    username "<gmail account name without @gmail.com>" password "<your app pass word>"
    using tlsv1
    with timeout 30 seconds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment