aspineux / pyzmail

Pyzmail is a high level mail library for Python, providing functions to read, compose and send emails
60 stars 31 forks source link

How to attach binary files to outgoing emails #14

Open nnako opened 7 years ago

nnako commented 7 years ago

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/:

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.