I have tried to attached a file to the mail using python. Code:
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIME
I prefer u guys to run the file as administrator for eg open cmd as administrator then type cd C:\into ur .py file path and then type python filename.py
it worked for me. good luck
you might did a little mistake in settings.py file.. check your code one more time in your settings file settings.py:
EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'your_email'
EMAIL_HOST_PASSWORD = 'your_password'
EMAIL_PORT = 587
EMAIL_USE_TLS=True
You need to login using your credential. Try:
smtpObj = smtplib.SMTP('smtp server name',port)
smtpObj .starttls()
smtpObj .login(email, password)
smtpObj.sendmail(sender, EmailId, message, msg.as_string() )
print "Successfully sent email"
The problem is that the DNS lookup for 'smtp server name' is failing - if this is your exact code then you can see why - if not and you have the valid qualified name for the SMTP server then you may have issues with the firewall/internet connection, etc., also port has to be set to a valid value to match your servers SMTP configuration, (usually port 25 but not absolutely always).
In my case was a host problem. Using debug mode, I spotted that in (host, port, 0, SOCK_STREAM) I got host=local and it should be host=localhost. In the run.py I defined localhost and the file hosts (c:\windows\system32\drivers\etc\hosts) was defined local. They have to be equal, otherwise you get the socket.gaieeror.
I know for sure that gaierror comes up when you are working from behind proxy.