On Mar 16, 2009, at 3:46 PM, Dana wrote: > I am wondering what the simplest way to send an attachment with > django- > contact-form (http://code.google.com/p/django-contact-form/) is. [...] > Im interested in just a simple example of sending a file along with > the other email information. I have subclassed the contact form and > just need to add an "attachment" field to the form.
I haven't worked with django-contact-form, but if you add a FileField to its ContactForm... attachment = forms.FileField(required=False) ... the modified save method could look something like: def save(self, fail_silently=False): email = EmailMessage(to = self.recipient_list, from_email = self.from_email, body = self.message(), subject = self.subject()) if self.cleaned_data['attachment']: file = self.cleaned_data['attachment'] if hasattr(file, 'path'): email.attach_file(file.path) else: email.attach(file.name, file.read()) email.send(fail_silently) That's an untested example; the point is you'll need to look at using the EmailMessage directly instead of via send_mail. Have a look at: http://docs.djangoproject.com/en/dev/topics/email/#the-emailmessage-and-smtpconnection-classes John --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---