简体   繁体   中英

Email not sending with django 1.9

I've been trying to get email working with a project I've been working on, I believe it's configured correctly, here my settings.py, the command I'm running, and the traceback I get when I stop it.

Email Configuration:

    #Email Configuration
    DEFAULT_FROM_EMAIL = #Email Address
    SERVER_EMAIL = #Email Address
    EMAIL_USE_TLS = True
    EMAIL_HOST = "smtp.gmail.com"
    EMAIL_PORT = 587
    EMAIL_HOST_USER = #Email Address
    EMAIL_HOST_PASSWORD = "**********"

Command:

    send_mail("Test", "Test", "from_email@gmail.com", ["to_email@gmail.com"], fail_silently=False)

Traceback:

    ^CTraceback (most recent call last):
      File "<console>", line 1, in <module>
      File "/home/django/DjangoApps/ConnectedFeedback/Py3_ENV/lib/python3.4/site-packages/django/core/mail/__init__.py", line 61, in send_mail
        return mail.send()
      File "/home/django/DjangoApps/ConnectedFeedback/Py3_ENV/lib/python3.4/site-packages/django/core/mail/message.py", line 292, in send
        return self.get_connection(fail_silently).send_messages([self])
      File "/home/django/DjangoApps/ConnectedFeedback/Py3_ENV/lib/python3.4/site-packages/django/core/mail/backends/smtp.py", line 100, in send_messages
        new_conn_created = self.open()
      File  "/home/django/DjangoApps/ConnectedFeedback/Py3_ENV/lib/python3.4/site-packages/django/core/mail/backends/smtp.py", line 58, in open
        self.connection = connection_class(self.host, self.port,     **connection_params)
      File "/usr/lib/python3.4/smtplib.py", line 242, in __init__
        (code, msg) = self.connect(host, port)
      File "/usr/lib/python3.4/smtplib.py", line 321, in connect
        self.sock = self._get_socket(host, port, self.timeout)
      File "/usr/lib/python3.4/smtplib.py", line 292, in _get_socket
        self.source_address)
      File "/usr/lib/python3.4/socket.py", line 503, in create_connection
        sock.connect(sa)
    KeyboardInterrupt

What am I doing wrong?

Edit: I ran telnet smtp.gmail.com 587 and it sat there for like 5 minutes but eventually connected

So it ended up just being an issue with google account security. Google was blocking the sign in attempt.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM