SMTP mailing TLS not working
Bug is in python smtplib and it's about the library not trying all possible login methods. It goes only with cram md5. Sending mail through gmail does not work. I managed to catch it by trying with own mail server, which refused login with cram md5 method.
I managed to fix it in /usr/local/lib/python2.7/smtplib.py
by changing default
preferred_auths = [AUTH_CRAM_MD5, AUTH_PLAIN, AUTH_LOGIN]
preferred_auths = [AUTH_LOGIN, AUTH_CRAM_MD5, AUTH_PLAIN]
Mail starts working.
#1 Updated by Jordan Hubbard over 4 years ago
Hmm. According to the python documentation for this (both in 2.7 and 3.4), this is deliberate as the login auth is considered "weaker" (perhaps when SSL is not used in conjunction with it). It's interesting that you're also the first person to report this issue, since it should really "fail downwards" in the preferred_auths list, it shouldn't just try CRAM_MD5 and then give up. Are you sure everything else in your mail configuration is correct?
#2 Updated by Branislav Kirilov over 4 years ago
- Hardware Configuration updated (diff)
Well my email setup is pretty straightforward. Username, pass, TLS, port 587.
I tried and got Authentication failed. Then i decided to try with gmail, if for some reason my mail server was the trouble. Then again i got the Authentication error.
Then decided to look more closely and found it.
If it should try CRAM_MD5 and give up, then there isn't a bug, but i don't think that this should be the normal behavior. Check this patch in smtplib https://bugs.python.org/issue6683
#7 Updated by Anonymous over 4 years ago
- Status changed from Screened to Closed: Behaves correctly
I face no issues sending mail through gmail with both SSL/TLS. I had to allow less secure apps on gmail though.
@Branislav: Kindly check if you have allowed less secured apps on gmail.
Turning off the less secured apps I get this error:
"Your test email could not be sent: (535, '5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/answer/14257 o7sm9587590pfa.37 - gsmtp')",
not the authentication error irrespective of 'preferred_auths' sequence.
For more info: