Skip to content

How to attach binary files to outgoing emails #14

@nnako

Description

@nnako

Hi,

thank you for this great module. Until now, it has provided a useful support.

Unfortunately, all the examples I have seen so far (even from the API documentation) show only how to attach TEXT FILES or a GIF IMAGE into an html email. What I want to do in short:

My application receives an email and extracts its attachments. After deciding what to do, some of these attachments (PDF, text, image,...) are to be forwarded to various revipients using the pyzmail module. But I can not figure out how to correctly tell the compose_mail() function how to do this. Here is my code so far:

# create new payload
payload, mail_from, rcpt_to, msg_id = pyzmail.compose_mail(
    ( <sendername> , <senderemail> ),
    [ <receiveremail> ],
    <subjectstring> ,
    'utf-8',
    ( <bodytext> , 'utf-8'),
    attachment=[( ...???... )]
    )

For example:

I have these three files within my folder /home/temp/:

  • test.PDF
  • test.PNG
  • test.TXT

How would I design the attachment part of the compose_mail() function to successfully get these files to the desired receiver?

Thank you in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions