email.send() 永远需要手动连接

email.send() taking forever for manual connection

django 1.4 版本

我知道 send_email。但是,我需要为来自数据库的每封电子邮件设置手动连接,因此使用 send() 函数。

from django.core.mail import EmailMessage, get_connection

e = EmailMessage('sub', 'body', to=['to@email.com'])

现在,它使用默认连接。

此时我想设置连接,所以我这样做了:

e.connection =    get_connection(backend='django.core.mail.backends.smtp.EmailBackend', username='email@gmail.com', password='password', host='smtp.gmail.com', port=465, use_tls=True)

e.send() #taking forever(means hanging there without moving to next command) Why ?

我清楚了吗?

尝试将 get_connection() 的端口参数从 port=465 (SSL) 更改为 port=587 (TLS)。