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: 380
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: 380
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: 1
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.

Post Reply