I use django storages and so .path raises
NotImplementedError: This backend doesn't support absolute paths.'
To avoid this, I just open the file, read it, guess the mimetype and close it later all the time, using .attach instead of .attach_file magic.
from mimetypes import guess_type from os.path import basename f = model.filefield f.open() msg.attach(basename(f.name), f.read(), guess_type(f.name)[0]) f.close()
source share