I am trying to write some add code to my app that accepts an email
from the user that contains attachments, adds those attachments to the
database and then sends an email containing those attachments.  I am
trying to get my code to work for the case were the attachment is an
outlook mail (ie, an rfc822 content-type). For other cases it is
working (ie, an msword doc or htm attachment), but there is something
trickier about sending out an rfc822 I think.

 I've got a small example of what I'm doing in my code I'm wondering
if anyone who understands email and FileFields could take a look.
Basically, I'm just trying to take the attached message, save it to a
django models.FileField, then send the contents of that FileField on
to recipients.

Here's my Attachment model:

class Attachment(models.Model):
    file = models.FileField('File', upload_to=get_attachments_path)
    filename = models.CharField('Filename', max_length=100)
    mime_type = models.CharField('MIME Type', max_length=30)

Here's my code that is parsing the message and encountering the rfc822
sub part:

if message.get_content_type() == 'message/rfc822':
    name = message.get_param("name")
    content = message.as_string() # ??? this may be wrong?
    mime_type = message.get_content_type()

    a = Attachment(filename=name, mime_type=mime_type)
    a.file.save(name, ContentFile(content))
    msg = EmailMultiAlternatives(subject, body, from_email, to, cc)
    msg.attach_file(a.file.path)
    msg.send()

The problem I'm having is that when msg.send() gets called, I get an
error associated with my attachment:

  File "/tools/aticad/1.0/platform/any/lib/python2.6/email/
message.py", line 189, in get_payload
    raise TypeError('Expected list, got %s' % type(self._payload))


I'm thinking that my argument to ContentFile() is wrong.  I'm giving
it message.as_string(), and I suspect that is wrong, but I can't
figure out what it should be.  Can anyone give me a hand?

Thank you for any pointers!

Margie



--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to