Page 2 of 2

Re: uMail - A lightweight SMTP client for MicroPython

Posted: Fri Sep 21, 2018 10:22 am
by shawwwn
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).

Re: uMail - A lightweight SMTP client for MicroPython

Posted: Fri Sep 21, 2018 10:41 am
by SpotlightKid
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()
       
    ...

Re: uMail - A lightweight SMTP client for MicroPython

Posted: Fri Sep 21, 2018 10:53 am
by shawwwn
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.
...

Re: uMail - A lightweight SMTP client for MicroPython

Posted: Fri Sep 21, 2018 11:02 am
by SpotlightKid
Ok, thanks for the workaround.

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

Re: uMail - A lightweight SMTP client for MicroPython

Posted: Sat Jan 05, 2019 11:16 am
by bakrag
Good job shawwwn. Your lib works perfect!
Thank you

Re: uMail - A lightweight SMTP client for MicroPython

Posted: Fri Jun 28, 2019 4:24 pm
by PM-TPI
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.