Commits

Anonymous committed 3df57c9

added support for MIMEBase email attachments. Slightly modified patch by Adam Alton

  • Participants
  • Parent commits fdff2a9

Comments (0)

Files changed (1)

         if message.bcc:
             gmsg.bcc = list(message.bcc)
         if message.attachments:
-            gmsg.attachments = [(a[0], a[1]) for a in message.attachments]
-        if isinstance(message, EmailMultiAlternatives):  # look for HTML
+            # Must be populated with (filename, filecontents) tuples
+            attachments = []
+            for attachment in message.attachments:
+                if isinstance(attachment, MIMEBase):
+                    attachments.append((attachment.get_filename(),
+                                        attachment.get_payload(decode=True)))
+                else:
+                    gmsg.attachments.append((a[0], a[1]))
+            gmsg.attachments = attachments
+        # Look for HTML alternative content
+        if isinstance(message, EmailMultiAlternatives):
             for content, mimetype in message.alternatives:
                 if mimetype == 'text/html':
                     gmsg.html = content