[Django]-No such file or directory attach_file in django email

3👍

attach_file takes a file from your filesystem, not a URL, so you have to use a local path to it

See https://docs.djangoproject.com/en/1.9/topics/email/

One, untested, possibility is to use the attach method instead and to download the file on the fly:

import urllib2
response = urllib2.urlopen("http://devuserapi.doctorinsta.com/static/pdfs/Imran_1066.pdf")
email.attach('IMran_1066.pdf',response.read(),mimetype="application/pdf")

It lacks error checking to make sure the file was downloaded, of course, and I haven’t actually tried it myself, but that might be an alternative for you.

Leave a comment