On Fri, Feb 21, 2014 at 4:28 PM, Patrick Beeson <pbee...@thevariable.com> wrote:
> Good morning y'all!
>
> I'm having a heck of a time figuring out what I'm doing wrong in attaching a
> file uploaded via a ModelForm to an email that's sent if the form is valid.
> Here's a link to my code on Stackoverflow:
> http://stackoverflow.com/questions/21938849/inmemoryuploadedfile-object-has-no-attribute-rfind-when-sending-email-with-a
>
> Thanks for your help!
>   resume = form.cleaned_data.get('resume')
>
>   #Compose message
>   email = EmailMessage()
>   email.body = '...'
>   email.subject = 'A new application has been submitted'
>   email.from_email = 'Job application <nore...@email.com>'
>   email.to = ['em...@email.com',]
>   email.attach_file(resume)

EmailMessage.attach_file() takes the path to a file on disk, not a
django.core.files.File subclass.

You may want to use EmailMessage.attach(), which takes a filename (as
listed in the email, not used for anything else), the contents of the
file as a string, and the content type of the file.

Both are documented here:

https://docs.djangoproject.com/en/1.6/topics/email/#the-emailmessage-class

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1JywdF-tyyF4jzqCKvs3D9ekx8-fVxKaWo4PH1i2D%3Dp-g%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to