Send email with smtp.office365.com. I get django SMTPServerDisconnected: Connection unexpectedly

1,853 views
Skip to first unread message

Ismael Cedano

unread,
Jan 12, 2015, 5:21:12 PM1/12/15
to opene...@googlegroups.com
Hi,
I tried with django shell. but it's still appear the same error.
but also, I tried with smtplib and its working good.

Platform: Fullstack.

I'm following the step belong to that URL:

Maybe the django version 1.4.16 has something to do with the error.

Can somebody bring [his|her] knowledge?


Thanks...



==> /edx/var/log/supervisor/lms_high_4tderr.log <==
2015-01-12 17:01:26,735 INFO 4537 [celery.worker.consumer] consumer.py:742 - consumer: Connected to amqp://cel...@127.0.0.1:5672//.

==> /edx/var/log/nginx/access.log <==
- - 127.0.0.1 - edx [12/Jan/2015:18:01:27 -0400]  "GET /xqueue/get_queuelen/?queue_name=certificates HTTP/1.1" 200 61 0.129 "-" "python-requests/2.3.0 CPython/2.7.3 Linux/3.5.0-23-generic"
- - 127.0.0.1 - edx [12/Jan/2015:18:01:32 -0400]  "GET /xqueue/get_queuelen/?queue_name=certificates HTTP/1.1" 200 61 0.127 "-" "python-requests/2.3.0 CPython/2.7.3 Linux/3.5.0-23-generic"

==> /edx/var/log/supervisor/lmstderr.log <==
2015-01-12 17:01:32,607 ERROR 4546 [edx.student] views.py:1990 - Unable to send reactivation email from "us...@domain.do"
Traceback (most recent call last):
  File "/edx/app/edxapp/edx-platform/common/djangoapps/student/views.py", line 1988, in reactivation_email_for_user
    user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/contrib/auth/models.py", line 374, in email_user
    send_mail(subject, message, from_email, [self.email])
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/mail/__init__.py", line 61, in send_mail
    connection=connection).send()
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/mail/message.py", line 248, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 92, in send_messages
    sent = self._send(message)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 110, in _send
    email_message.message().as_string())
  File "/usr/lib/python2.7/smtplib.py", line 721, in sendmail
    self.rset()
  File "/usr/lib/python2.7/smtplib.py", line 460, in rset
    return self.docmd("rset")
  File "/usr/lib/python2.7/smtplib.py", line 385, in docmd
    return self.getreply()
  File "/usr/lib/python2.7/smtplib.py", line 361, in getreply
    raise SMTPServerDisconnected("Connection unexpectedly closed")
SMTPServerDisconnected: Connection unexpectedly closed

==> /edx/var/log/lms/edx.log <==
Jan 12 18:01:32 ubuntu [service_variant=lms][edx.student][env:sandbox] ERROR [ubuntu  4546] [views.py:1990] - Unable to send reactivation email from "us...@domain.do"
Traceback (most recent call last):
  File "/edx/app/edxapp/edx-platform/common/djangoapps/student/views.py", line 1988, in reactivation_email_for_user
    user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/contrib/auth/models.py", line 374, in email_user
    send_mail(subject, message, from_email, [self.email])
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/mail/__init__.py", line 61, in send_mail
    connection=connection).send()
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/mail/message.py", line 248, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 92, in send_messages
    sent = self._send(message)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 110, in _send
    email_message.message().as_string())
  File "/usr/lib/python2.7/smtplib.py", line 721, in sendmail
    self.rset()
  File "/usr/lib/python2.7/smtplib.py", line 460, in rset
    return self.docmd("rset")
  File "/usr/lib/python2.7/smtplib.py", line 385, in docmd
    return self.getreply()
  File "/usr/lib/python2.7/smtplib.py", line 361, in getreply
    raise SMTPServerDisconnected("Connection unexpectedly closed")
SMTPServerDisconnected: Connection unexpectedly closed

Ismael Cedano

unread,
Jan 13, 2015, 12:43:19 PM1/13/15
to opene...@googlegroups.com
I solved it.
This was the issue: It can't log in because I didn't edit the user and password on lms.auth.json.
The server try to send something without the user authentication 

The email's setting on SMTP protocol  for your Production (Full stack) environment LMS:

Go to lms.envs.json and edit: 
    "DEFAULT_FEEDBACK_EMAIL": "us...@domain.com",
    "DEFAULT_FROM_EMAIL": "us...@domain.com",
    "EMAIL_BACKEND": "django.core.mail.backends.smtp.EmailBackend",
    "EMAIL_HOST": "smtp.gmail.com",
    "EMAIL_PORT": 587,
    "EMAIL_USE_TLS": true

For set the user and password go to lms.auth.json and edit:
    "EMAIL_HOST_USER": "us...@domain.com"
    "EMAIL_HOST_PASSWORD": "user_password"

Why?
If you go to lms/envs/awy.py you would see that 

line 88: with open(CONFIG_ROOT / CONFIG_PREFIX + "env.json") as env_file:
    ENV_TOKENS = json.load(env_file)

It's take the lms.env.json for:
 Email backend, host, port and tls

But in the line 214:
with open(CONFIG_ROOT / CONFIG_PREFIX + "auth.json") as auth_file:
    AUTH_TOKENS = json.load(auth_file)

It's take lms.auth.json for:
    user and password.
Reply all
Reply to author
Forward
0 new messages