WebFaction
Community site: login faq

I have a script which is executed with received emails via mail2script. What is an easy way to extract attachment from the email and save to a file? I could make an assumption that there is always one and only attachment.

Thanks, Adam

asked 07 Oct '12, 00:50

sapek
312
accept rate: 0%


That depends on the programming language that you are using to parse the email.

Our mail2script feature sends the contents of the email as standard input, so you should be able to parse them easily.

If you are using python, the email library is the best option. It is very well documented and it has some examples at the end.

We don't have mail2scipt related tips in our documentation, so I did a quick search on Google and found a couple of articles that look good as a starting point:

  • http://stackoverflow.com/questions/4067937/getting-mail-attachment-to-python-file-object
  • http://blog.codeus.net/how-to-extract-email-contents-nicely-with-python/
  • http://janeelix.com/piers/python/save_all_attachments

You can probably find some other good choices in these search results.

permanent link

answered 07 Oct '12, 04:11

iliasr ♦♦
2.1k14
accept rate: 35%

Thx. I ended up using munpack from a bash sript.

(07 Oct '12, 14:45) sapek
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×261
×6
×4

question asked: 07 Oct '12, 00:50

question was seen: 5,263 times

last updated: 07 Oct '12, 14:50

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM