uMail - A lightweight SMTP client for MicroPython

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
shawwwn
Posts: 16
Joined: Tue Feb 06, 2018 5:22 am

Re: uMail - A lightweight SMTP client for MicroPython

Post by shawwwn » Fri Sep 21, 2018 10:22 am

Let me put it this way:

The client will switch to TLS encryption once it sees STARTTLS in server's response, regardless of the status of 'ssl'.

It all depends on server's reply. If you want to enforce a secure connection, then you should let the server to always reply STARTTLS.

Setting 'ssl=True' is just for encrypting the initial connection(i.e., when you connecting to a port that only supports secure connection).

SpotlightKid
Posts: 463
Joined: Wed Apr 08, 2015 5:19 am

Re: uMail - A lightweight SMTP client for MicroPython

Post by SpotlightKid » Fri Sep 21, 2018 10:41 am

I've already understood all that after your first reply.

But what if I have no control over the server and the server doesn't enforce but supports STARTTLS and I want to initiate STARTTLS from the client? With the CPython smtplib module, I would do something like this:

Code: Select all

def send_email(from, to, msg, host='localhost', user=None, password=None, ssl=False, starttls=False):
    if ssl:
        smtp_class = smtplib.SMTP_SSL
        port = 465
    else:
        smtp_class = smtplib.SMTP
        port = 587

    smtp = smtp_class(host, port)
 
    if starttls:
       smtp.starttls()
       smtp.ehlo()
       
    ...

shawwwn
Posts: 16
Joined: Tue Feb 06, 2018 5:22 am

Re: uMail - A lightweight SMTP client for MicroPython

Post by shawwwn » Fri Sep 21, 2018 10:53 am

I see, but adding a 'starttls=True|False' besides 'ssl' would be too confusing for many users.
There is however a hack you can do (without changing the code).

Code: Select all

smtp.SMTP('xxx', xx)
# after smtp instance is initialized
code, _ = smtp.cmd('STARTTLS')
assert code == 220
smtp._sock = ussl.wrap_socket(smtp._sock)
# then proceed to login, etc.
...
Last edited by shawwwn on Fri Sep 21, 2018 11:11 am, edited 1 time in total.

SpotlightKid
Posts: 463
Joined: Wed Apr 08, 2015 5:19 am

Re: uMail - A lightweight SMTP client for MicroPython

Post by SpotlightKid » Fri Sep 21, 2018 11:02 am

Ok, thanks for the workaround.

I don't think that a separate option for starttls would be too confusing, but opinions differ :)

bakrag
Posts: 1
Joined: Sat Jan 05, 2019 11:10 am

Re: uMail - A lightweight SMTP client for MicroPython

Post by bakrag » Sat Jan 05, 2019 11:16 am

Good job shawwwn. Your lib works perfect!
Thank you

PM-TPI
Posts: 75
Joined: Fri Jun 28, 2019 3:09 pm

Re: uMail - A lightweight SMTP client for MicroPython

Post by PM-TPI » Fri Jun 28, 2019 4:24 pm

Using a Pycom GPy board these are my results...

GoDaddy ('smtpout.secureserver.net', 465, ssl=True) works

Offie365 ('smtp.office365.com', 587, ssl=xxxx)
# SSL True = OSError: [Errno 113] EHOSTUNREACH
# SSL False = AssertionError: auth error 535

Outlook Mail ('smtp-mail.outlook.com', 587, ssl=xxxx)
# SSL True = OSError: [Errno 113] EHOSTUNREACH
# SSL False = AssertionError: auth error 535

don't want to use "Allow less secure apps"
G mail ('smtp.gmail.com', 465, ssl=xxxx)
# SSL True = OSError: [Errno 113] EHOSTUNREACH
# SSL False = OSError: [Errno 113] EHOSTUNREACH

anyone able to connect to these email servers?
or other servers?

What am I missing or not understanding.

mikronauts
Posts: 13
Joined: Thu Nov 03, 2016 10:12 pm

Re: uMail - A lightweight SMTP client for MicroPython

Post by mikronauts » Wed Sep 04, 2019 12:41 am

I tried to use this great looking library today, unfortunately it had an array index issue on line 30 of umail.py

I submitted an issue on the github

https://github.com/shawwwn/uMail/issues/4

I am using an esp32 (devkitc), latest micropython, upycraft ide.

I would appreciate any suggestions.

mikronauts
Posts: 13
Joined: Thu Nov 03, 2016 10:12 pm

Re: uMail - A lightweight SMTP client for MicroPython

Post by mikronauts » Wed Sep 04, 2019 7:17 pm

Great library, fantastic support.

My bad, I had connecting to my wifi commented out.

taropal
Posts: 2
Joined: Thu Oct 17, 2019 11:56 pm

Re: uMail - A lightweight SMTP client for MicroPython

Post by taropal » Fri Oct 18, 2019 12:41 am

Hi I am new to Micropython running on ESP32 port. I would like to know how to install this umail module onto the chip. I tried upip to install package but with no avail from the getlib repository. Please advice..

taropal
Posts: 2
Joined: Thu Oct 17, 2019 11:56 pm

Re: uMail - A lightweight SMTP client for MicroPython

Post by taropal » Sun Oct 20, 2019 2:55 am

Hi all,
gotten a bit further and uploaded umail.py into the ESP32 and ran the import command
during this line,
smtp = umail.SMTP('smtp.gmail.com', 465, ssl=True)

it reported:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'SMTP'

did i do something wrong? Please advice... Thanks.

Post Reply