0

django 1.4 version

I know about send_email. But, I need to set manual connection for every email from db so using send() function.

from django.core.mail import EmailMessage, get_connection

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

Now, it uses default connection.

I want to set connection at this point, so I did this:

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 ?

Am I clear ?

Community
  • 1
  • 1
user2349115
  • 1,288
  • 2
  • 17
  • 34

1 Answers1

1

Try changing the port argument to get_connection() from port=465 (SSL) to port=587 (TLS).

mhawke
  • 84,695
  • 9
  • 117
  • 138
  • I just found that too, thanks for the answer, +1. But, those port number used to work a month back, what happened now ? Oh, 465 when I use ssl and 587 when I use tls ? – user2349115 Jan 23 '15 at 09:07
  • @user2349115: AFAIK nothing has changed at the gmail end. Perhaps you were using SSL previously? – mhawke Jan 23 '15 at 09:12
  • I donno I am confused. Current settings are ssl to true, and port set to 465. Ofcourse, now I changed to ssl false, tls true, and port to 587 which is working. Thanks for the answer. – user2349115 Jan 23 '15 at 09:18