How to handle attachments passed via Postfix

Anthony Papillion anthony at cajuntechie.org
Mon Oct 12 17:52:31 EDT 2015


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

On 10/12/2015 3:58 AM, Chris Angelico wrote:
> On Mon, Oct 12, 2015 at 6:17 PM, Anthony Papillion 
> <anthony at cajuntechie.org> wrote:
>> I'm writing a script that will have email with attachments passed
>> to it via Postfix.  Postfix is properly passing the email to the
>> script but I'm not quite sure how to get at the attachment.  What
>> I need to do is save the attachment out to the filesystem.
>> 
>> Can anyone point me in the right direction?
> 
> If I understand the situation correctly, you're getting a 
> MIME-formatted email, and want to decode it into a usable
> attachment - right?
> 
> Python includes a package for teasing apart RFC[2]822 format
> emails:
> 
> https://docs.python.org/3/library/email.html
> 
> Check out the email.parser module, or the convenience function 
> email.message_from_string - you should be able to get at the
> different parts (including attachments) from there.
> 

Many thanks! Checking it out now. Sounds like exactly what I'm looking
for.

Anthony

-----BEGIN PGP SIGNATURE-----

iQIcBAEBCgAGBQJWHCufAAoJEAKK33RTsEsVfeUP/3YWWDwVglwHXkHGrY3AkWol
yyTeJyy+s8RQvza1gHcR3yv2gZs7PAI8azFjkMmlsicaB+dqdP1ffxd2eXK3TVlh
GTOuCe7dHNgJ4EMpREr3RtJVbvQBX3ygmZaZY9jqPRCpG40TfOCaEOXjGABLukwi
DP9j65tyIYRJsImmQ4RJ6L2AcrgGC3QTU1wCPPWaYD9AWLFyfR4be02vGGZODbYs
QnKw1MrHrQBWMYaVKlhkvHVJIa68q/wIH4yPfE8tPejykRQ0OFUDfp8a9zveNU7U
zIjeVU02jL3ijGXK1LxNz3mtt+aRletecOFbLtCMLY9TLwGTquXRyQzl28oOukh+
Uy/rYf9ZK8g2qrOEELyJXy4x0K6MpTdF+hN85oYkCl802uEsqlxUsU/EocUs6uIX
GIXrevDSvdQDbujMUPg4TQKmkhNN5/fC40NQGFd/xcxljTqHZ/bl4MinDT9ZxYFk
OLwEpCVZfTMJvYxGEfBS1GQvKxeRKzPgXeV70YgXh0GIl339Bq1znpObnlYNuVki
cBRqos2RUAanzgkQ6jqoE0KknP/wPZL/nJA1MR67lV64j5zqMD/b+Pw44K/u9QNP
YZnXzto8EUJ9Zs4i7LrZcFuRpE+WjFyP39XPGiMZN7+/S9++CVfgu0SLLT3VrHWc
v7WzAa3wNEnR8O35bhvH
=xwRy
-----END PGP SIGNATURE-----



More information about the Python-list mailing list