shawwwn/uMail

Failure to access Gmail's SMTP server ESP32

davefes opened this issue · 9 comments

I am trying to figure out why umail, on this platform, sometimes fails. I have attempted to log assert errors by doing this:
try: smtp = umail.SMTP('smtp.gmail.com', 465, ssl=True) except AssertionError as error: try: with open('errors.txt', 'a') as outfile: outfile.write(str(error) + '\n') except OSError: print('oops')
but have been unsuccessful. Could you tell me the correct way to log assert errors?

Thank you,
Dave

  1. In order to to use smtp on gmail, you have to turn on the 'less secure app' option on your google account first.
    https://support.google.com/accounts/answer/6010255

  2. Maybe a good idea to start with base class Exception to catch all first

try:
    assert 1==2, 'assertion failed'
except Exception as e:
    print('err:', e)

I have had "less secure" on for the last 6 months. Thank you for the example.
Cheers, Dave

You can start with wrapping everything.

try:
    smtp = umail.SMTP('smtp.gmail.com', 587, username='my@gmail.com', password='mypassword')
    smtp.to('someones@gmail.com')
    smtp.send("This is an example.")
    smtp.quit()
except Exception as e:
    print('err:', e)

About 50% fail-rate with error -202. So, I tried catching the error:

        import ussl
        self.username = username
        addr = usocket.getaddrinfo(host, port)[0][-1]
        try:
           with open('errors.txt', 'a') as outfile:
                outfile.write('addr response ' + str(addr) + '\n')
        except OSError:
            print('oops')

Problem is that when something goes wrong in:

addr = usocket.getaddrinfo(host, port)[0][-1]

that nothing is returned in addr and umail seems to bail-out. Is something happening at the usocket level?

" Accepted 202
The request has been accepted for processing, but the processing has not been completed. The request may or may not eventually be acted upon, as it may be disallowed when processing actually takes place. there is no facility for status returns from asynchronous operations such as this."

getaddrinfo() is used to translate a domain name(ie. google.com) to an ip address(ie. 8.8.8.8).
If it fails, the first thing you need to look into is your DNS settings(or internet connection in general).

Thank you for the great support! I am setting a static address on the ESP32 and I think the problem was I was setting the 3G hotspot as the DNS. Tried changing to 8.8.8.8 and 5 out of 5 so far.

Will close this tomorrow after some stress testing.

Really appreciate being able to use uMail on the ESP32 to access Gmail's SMTP server, thanks again.