#9575 closed Uncategorized (invalid)
email configuration using starttls
Reported by: | paigeadele | Owned by: | nobody |
---|---|---|---|
Component: | Core (Mail) | Version: | 1.0 |
Severity: | Normal | Keywords: | starttls gmail |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
K, sent this to the django-registration people and they rejected it, if you won't take it noone will. They insist it's in your court.
doesn't work
ACCOUNT_ACTIVATION_DAYS=7
EMAIL_HOST='smtp.gmail.com'
EMAIL_USE_TLS=1
EMAIL_PORT=465
EMAIL_HOST_USER='webdev@…'
EMAIL_HOST_PASSWORD='excluded'
works
ACCOUNT_ACTIVATION_DAYS=7
EMAIL_HOST='smtp.gmail.com'
EMAIL_USE_TLS=1
EMAIL_PORT=587
EMAIL_HOST_USER='webdev@…'
EMAIL_HOST_PASSWORD='excluded'
Problem: if you use port 465, it will literally hang indefinitely and you
won't know what the heck is going on, it doesn't even get to the point
where it shows the HTTP request after the registration form POSTS in the
output of manage.py runserver.
The only reason I thought to try the alternate port number was because I
rememebered that when I first tried to register it tried to connect to the
mail server on localhost which I don't have (default settings) so I knew
that it wasn't the registration form because that actually gave me an
error. Google's documentation suggests that I can use 465 and 587 so I
figured eh, I'll give 587 a try and sure enough it worked.
Here's the google smtp server documentation I'm not sure what the
difference is between port 465 and 587, compatibility maybe?
http://mail.google.com/support/bin/answer.py?hl=en&answer=13287
Change History (4)
comment:1 by , 16 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 16 years ago
GMail's doc is surely lacking here. They throw out these ports and say 'use one' without giving any guidance on when each is appropriate, probably because they figure the technical mumbo-jumbo required to explain that would be over the heads of 99.9999% of their users. Which is true, but still they could do a better job of indicating that probably one or the other is going to work with any particular mail client, so try one and if it doesn't work try the other.
587 is the one to use for any Python smtplib.SMTP() connection. 465 works for others, I forget which, but I know I have seen reports of changing the port to 465 being a solution. From the behavior of GMail's servers in response to telneting to these ports, 465 apparently works for clients that use a protocol where the client speaks first on the connection. Python's smtplib does not speak first.
The problem with GMail's port 465 when using Python's smtplib.SMTP to send mail is that GMail's servers accept a connection to port 465 but don't send anything in response. Port 587, on the other hand, accepts the connection and immediately sends something like "220 mx.google.com ESMTP 12sm15403552qbw.2". Python's routine that is establishing the mail connection first creates a socket connection (which does have a timeout), and then waits for the server to send a message on the connection (with no timeout on the socket read). So, if the server never sends anything, smtplib.SMTP() hangs. Presumably eventually the server on port 465 will close this connection on which the client has sent no data, and that will wake up the blocking read(), but I don't know how long that will take.
comment:4 by , 12 years ago
Easy pickings: | unset |
---|---|
Severity: | → Normal |
Type: | → Uncategorized |
UI/UX: | unset |
To use port 465, you need to call smtplib.SMTP_SSL()
. Currently, it looks like Django only uses smtplib.SMTP()
.
By the way, the socket hangs indefinitely because the timeout parameter for smtplib.SMTP()
defaults to socket._GLOBAL_DEFAULT_TIMEOUT
, which defaults to no timeout. I think it is important to set a timeout, because the SMTP server can suddenly misbehave at any moment (due to misconfiguration, mail server running out of space, etc), leaving the connection stalled for days or even weeks.
I'm unclear as to what exactly you see as the course of action here. If GMail is suggesting you should use port 465 and that isn't correct, the fault lies with the GMail documentation, not Django.
Django provides an EMAIL_PORT option. You are free to use whatever value works. If, when pointing at GMail, port 465 doesn't work, but port 587 does, then set EMAIL_PORT=587 and move on.
Unless:
1) there is something explicitly wrong with Django's SMTP handling for port 465, or
2) there is a Django default that specifies port 465, or
3) there is Django documentation suggesting that port 465 will work
I can't see anything that we can do. (2) and (3) aren't true (I can't find any reference to port 465 in docs or settings). Django doesn't contain any special handling for port 465, so I can't see how (1) could be true either. Therefore, there isn't much we can do to fix this problem. Unless you can propose a course of action that is actually in Django's domain, I'm marking this ticket invalid.