3

Few hours back I have posted a post related to "Django email sending API" and its error. So I thought that first I should try something with "smtplib". Unfortunately, after struggling with "smtplib", I realise that it will also not work, because something is wrong with my code or my network or my machine which I am not able to figure out.

Can any body help me regarding to this?

As of now, after struggling a lot, I have tried hundreds of solution posted here and there and also I have tried to resolve with myself but nothing is working in my case kindly help.

Code is given bellow.

import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText

import socks



socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS4, "172.16.0.2", '8084')
socks.wrapmodule(smtplib)

#smtp = smtplib.SMTP()

msg = MIMEMultipart()
msg['From'] = 'my@yahoo.com'
msg['To'] = 'example@gmail.com'
msg['Subject'] = 'simple email in python'
message = 'here is the email'
msg.attach(MIMEText(message))

mailserver = smtplib.SMTP('smtp.mail.yahoo.com',465)
# identify ourselves to smtp gmail client
mailserver.ehlo()
# secure our email with tls encryption
mailserver.starttls()
# re-identify ourselves as an encrypted connection
mailserver.ehlo()
mailserver.login('my@yahoo.com', 'pswd12345678')

mailserver.sendmail('my@yahoo.com','example@gmail.com',msg.as_string())

mailserver.quit()

This is the error coming again and again:

Traceback (most recent call last):
  File "import_mail.py", line 21, in <module>
    mailserver = smtplib.SMTP('smtp.mail.yahoo.com',465)
  File "/usr/lib/python2.7/smtplib.py", line 256, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python2.7/smtplib.py", line 316, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python2.7/smtplib.py", line 291, in _get_socket
    return socket.create_connection((host, port), timeout)
  File "/usr/lib/python2.7/socket.py", line 557, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -3] Temporary failure in name resolution
jax
  • 3,927
  • 7
  • 41
  • 70
  • I am facing the similar issue, any update on the issue? – o12d10 Dec 22 '17 at 00:19
  • @yashgarg this Quetion was posted by me long ago, though, I have resolved this error later on but now I forgot what exactly I did. – jax Dec 22 '17 at 05:05
  • Not an issue. Do you happen to remember if there is a daily email limit in the smtplib.py – o12d10 Dec 23 '17 at 22:13
  • No I am sure that it was not relate to "daily email limit in the smtplib.py" – jax Dec 24 '17 at 10:13

2 Answers2

5

This error is raised as the 'EMAIL_BACKEND' definition is missing from the settings file. Make sure that the settings.py file contains the following line:-

  EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

IF you`re using the gmail account to set up a default interactive mail, use the following values:-

  EMAIL_HOST = 'smtp.gmail.com'
  EMAIL_PORT = 587 #PORT NO
  EMAIL_HOST_USER = #e-MAIL ID
  EMAIL_HOST_PASSWORD = #PASSWORD
eager_learner
  • 152
  • 1
  • 9
0

My system had not a DNS configured and I resolved this issue configuring a google DNS or an openDNS.

Okar_Mx
  • 11