kootenpv / yagmail

Send email in Python conveniently for gmail using yagmail
MIT License
2.66k stars 265 forks source link

Add support SSL #80

Closed Godod closed 7 years ago

kootenpv commented 7 years ago

Hey, thanks a lot for attempting it, I missed it!

I'm getting:

ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:744)

when using smtp_ssl=True, googling finds that it means that it is making a HTTP request.

Godod commented 7 years ago

Hello. If you want use HTTPS instead of HTTP, you need set smtp_ssl=True, else you could use HTTP by default without set smtp_ssl=True.

kootenpv commented 7 years ago

I installed your commit and used smtp_ssl=True, but then it gave me the error which indicates that when trying to use SSL like that it was using HTTP (thus not working). Are you sure you're using SSL?

Godod commented 7 years ago

Yes, I sure. I'm using 465 port for my mail (not gmail) and it worked normally. I'm using this options:

self._credentials = {
            'user': settings.get('mail.username'),
            'password': settings.get('mail.password'),
            'host': settings.get('mail.host'),
            'port': int(settings.get('mail.port')),
            'smtp_ssl': strtobool(settings.get('mail.ssl', 'true')),
            'smtp_starttls': False
        }

I can show you sending email traceback, if you want.

kootenpv commented 7 years ago

Thanks a lot! Indeed, I was trying to use oauth2, and the port is not used correctly then (you can see the "login" method on SSL overriding the port).

I guess what needs to be done is to make the port change in case SSL is being used, then it should work. Except for oauth2 it currently does not.

It will make more sense to make a single login; it has to be refactored :)

kootenpv commented 7 years ago

In commit https://github.com/kootenpv/yagmail/commit/4797f4868d59e0136189560ee28fbcb352543457 I did the refactoring! Very happy about the result :)

kootenpv commented 7 years ago

On PyPi since yagmail==0.10.190, please upgrade with:

pip install -U --no-cache yagmail   # python 2 most likely
pip3 install -U --no-cache yagmail # python 3