Sending a FileField attachment by email

21 views
Skip to first unread message

Hugo Kitano

unread,
Sep 9, 2015, 4:49:45 PM9/9/15
to Django users

I'm having problems sending a FileField attachment via email. This should send an email, but doesn't. Is there something I have to configure in my gmail account for this to work?


settings.py:


EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'em...@gmail.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

views.py:


#i.output is the FieldFile
message = 'Thanks for using our website!'
email = EmailMessage('Analysis', message, settings.EMAIL_HOST_USER, [toEmail])
email.attach(filename, i.output.read())
email.send()

I've even received an email from Gmail telling me a sign-in attempt was prevented. Any help? Thanks!

Reply all
Reply to author
Forward
0 new messages