problem with alarm.py on gmail

138 views
Skip to first unread message

fLsh

unread,
Jul 30, 2021, 8:14:19 AM7/30/21
to weewx-user
Hello all together,

it seems I can't get the alarm.py running.
I always get an error during authentication to google server:
alarm: SMTP mailer refused message with error (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8  https://support.google.com/mail/?p=BadCredentials j13sm1499223wms.24 - gsmtp')

I am using the following config:

[Alarm]
    expression = outTemp > 24.0
    time_wait = 1800
    smtp_host = smtp.gmail.com
    smtp_user = relaymtx
    smtp_password = mypassword
    from = weewx
    mailto = mymail
    subject = Alarm from weewx!
    count_treshold = 10

I did several attempts in changing the smtp_user by adding @gmail.com which results in the same error.
Also tried adding port 465 to smtp.gmail.com:465 without success.
IMAP access is activated in the gmail-account.
So any help would be appreciated.

Best regards,
Matthias

gjr80

unread,
Jul 30, 2021, 8:22:30 AM7/30/21
to weewx-user
What about smtp_host = smtp.gmail.com:587 ? If you search the forums for ‘smtp.gmail’ you will find a few threads where folks have had gmail smtp issues plus a few suggestions for troubleshooting.

Gary

Doug Jenkins

unread,
Jul 30, 2021, 9:47:49 AM7/30/21
to weewx-user
Matthias:

Gmail requires a SSL Authenticated connection using TLS. It is configured to look for traffic from port 587. 

I looked at the alarm.py code on the master branch in github (weewx/alarm.py at master · weewx/weewx (github.com) and it is already set appropriately for the smtplib package for SSL, but the port is not expressively set, so it is defaulting to port 465 per the smtplib package spec ( smtplib — SMTP protocol client — Python 3.9.6 documentation)

So I would do the following:
1. I would try Gary's suggestion in putting the port after the smtp_host line. 
2. If that does not work, then I would modify the alarm.py code to supply the port in this manner


# Starting at line 168
try:

# First try end-to-end encryption
s = smtplib.SMTP_SSL(self.smtp_host, timeout=self.timeout, port=587)
syslog.syslog(syslog.LOG_DEBUG, "alarm: using SMTP_SSL on port 587")

Please let me know if that helps.

Doug

fLsh

unread,
Jul 30, 2021, 10:08:05 AM7/30/21
to weewx-user
Thank you very much for your suggestions.
I tried port 587 in weewx.conf which did not work (both with username + @gmail.com and without).

Then I tried adding the port in the alarm.py with the following result (botth with/without @gmail.com in weewx.conf)
Jul 30 16:00:24 loxberry /weewxd: alarm: Alarm expression "outTemp > 24.0" evaluated True at 2021-07-30 16:00:00 CEST (1627653600)
Jul 30 16:00:24 loxberry /weewxd: alarm: unable to use SMTP_SSL connection.
Jul 30 16:00:24 loxberry /weewxd: alarm: unable to sound alarm. Reason: [Errno 111] Connection refused


code in alarm.py:
try:
            # First try end-to-end encryption
            s = smtplib.SMTP_SSL(self.smtp_host, timeout=self.timeout, port=587)
            syslog.syslog(syslog.LOG_DEBUG, "alarm: using SMTP_SSL on port 587")

Doug Jenkins

unread,
Jul 30, 2021, 10:17:03 AM7/30/21
to weewx-user
Matthias:

I will give this a go on my weewx instance and see what the issue is. I have a gmail account and have utilized this smtp library in the past with other Python 3 solutions. I will let you know.

Doug

Doug Jenkins

unread,
Jul 30, 2021, 10:57:03 AM7/30/21
to weewx-user
So I made the adjustments to my alarm.py and gave it a go with my weather station reporting when the temperature is over 70f (which is everyday here in Sunny Florida!) In both cases using port 587 and 465 with my Google Workspace account (aka paid gmail for a domain), I received alerts from my machine. So it is most likely not a port problem.

So what I recommend is going on the terminal and checking to see if you can connect directly to smtp.gmail.com at ports 465 and 587 on the machine that is hosting your weewx instance:

telnet smtp.gmail.com 587

If it responds back with a 200, then type in HELO <yourdomain> and see if it responds back. 

If you get a connection refused, then you are having problems connecting to that server. I would diagnosis and research the problem on your end further (eg firewalls, gmail security setup, etc.)

Doug

fLsh

unread,
Jul 30, 2021, 12:51:25 PM7/30/21
to weewx-user
so telnet .. gives me the following:
220 smtp.gmail.com ESMTP a207sm2856704wme.27 - gsmtp
Is that good?

fLsh

unread,
Jul 30, 2021, 1:10:21 PM7/30/21
to weewx-user
What exactly do you mean by domain? Ip of my router?

fLsh

unread,
Aug 2, 2021, 4:10:24 AM8/2/21
to weewx-user
Ok I fixed it.
I thought I had allowed unsecure 3rd party apps but apparently that was not true.
So I allowed that, retried with the following options:
 expression = outTemp > 24.0
    time_wait = 600
    smtp_host = smtp.gmail.com:587
    smtp_user = myu...@gmail.com
    smtp_password = my pw
    from = weewx
    mailto = receipt

    subject = Alarm from weewx!
    count_treshold = 10

... and it worked!! Thx for the help :)
Reply all
Reply to author
Forward
0 new messages