I figured it out. If someone wants to know how to do it, here is the
snippet:

http://www.djangosnippets.org/snippets/1063/





On Sep 17, 9:54 am, saeb <[EMAIL PROTECTED]> wrote:
> Can some please help me with this issue? I have been trying all sorts
> of stuff for past few hours and django documentation seems
> insufficient. I can see that the file is loaded in memory, but doesn't
> get attached. I couldn't find any examples dealing with this sort of
> case.
> thanks again.
>
> On Sep 16, 11:47 pm, saeb <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> >    I am trying to send a file as an attachment in an email.  It works
> > fine when I attachment file is hardcoded. But when I try to use
> > FileInput widget, I just get the filename in request.FILES dictionary.
> > Is it possible to get full path of the file?  Am I using wrong widget
> > for this purpose? Can anyone please help me, thanks
>
> > ---Form ----
>
> > class EmailForm(forms.Form):
> >         subject = forms.CharField(max_length=100)
> >         attachment = forms.CharField(widget = forms.FileInput)
> >         email = forms.EmailField()
> >         message = forms.CharField()
> > ---Views-----
>
> > def send_email(request):
> >         if request.method != 'POST':
> >                 form = EmailForm()
> >                 return render_to_response('admin/Email.html', 
> > {'email_form': form})
>
> >         form = EmailForm(request.POST, request.FILES)
> >         if form.is_valid():
> >                 subject = form.cleaned_data['subject']
> >                 message = form.cleaned_data['message']
> >                 email = form.cleaned_data['email']
> >                 attachment = request.FILES['attachment']
> >                 try:
> >                         mail = EmailMessage(subject, message, 
> > settings.EMAIL_HOST_USER,
> > [email])
> >                         mail.attach_file(attachment)
> >                         mail.send()
> >                         return render_to_response('admin/Email.html', 
> > {'message': 'Sent
> > email']})
> >                 except:
> >                         return render_to_response('admin/Error.html', 
> > {'message': 'Error'})
> >         return render_to_response('admin/Email.html', {'message': 'Unable to
> > send email. Please try again later'})
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to