zhangyunhao116 / zmail

Zmail makes it easier to send and retrieve emails in python3
MIT License
433 stars 112 forks source link

TypeError: Can not use ssl and tls together #81

Closed ZuoGuocai closed 4 years ago

ZuoGuocai commented 4 years ago

I usually send email via exchange servers like this :

def sendMail(body):
    url = 'my_smtpserver'
    conn = smtplib.SMTP(url,25)
    conn.starttls()
    user,password = ('username','password')
    conn.login(user,password)

but I can't find smtp tls in your documents. Can I send email through zmail to use tls support?

When I set the key of zmail.server like smtp_tls=True,but neither not work correctly. The error message in the below

 File "/usr/local/lib/python3.8/site-packages/zmail/abc.py", line 31, in __init__
    raise TypeError('Can not use ssl and tls together.')
TypeError: Can not use ssl and tls together.
zhangyunhao116 commented 4 years ago

Sure. But SMTP TLS can only be used alone, since you can't use ssl and tls together as the TypeError says. All you need to do is just disable SSL and enable TLS by smtp_tls=True, smtp_ssl=False. In fact, TLS or SSL will enabled automatically, you don't need to care about this in most cases.

ZuoGuocai commented 4 years ago

Sure. But SMTP TLS can only be used alone, since you can't use ssl and tls together as the TypeError says. All you need to do is just disable SSL and enable TLS by smtp_tls=True, smtp_ssl=False. In fact, TLS or SSL will enabled automatically, you don't need to care about this in most cases.

I got it. As you said, I try to send email via zmail successfully. The detail config in the below. Thanks for your reply.

 server = zmail.server('username', 'password', smtp_host='exchange-server-ip', smtp_port=25,smtp_tls=True, smtp_ssl=False)

smtp_tls=True, smtp_ssl=False may be a good idea, If I don't config any of them , I would got the error message like that ssl.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:1108), I guess the reason is that I only open 25 port with tls in the exchange server, but the zmail may be connet to the exchange server via 587 or 465 when the auto model.

zhangyunhao116 commented 4 years ago

In this case, looks like zmail use the default config, since it can't find the config in https://github.com/ZYunH/zmail/blob/master/zmail/info.py , i guess you use a private email server?