login community 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 Oct 07 '12 at 00:50

sapek's gravatar image

sapek
31


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.

answered Oct 07 '12 at 04:11

iliasr's gravatar image

iliasr ♦♦
7763

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

(Oct 07 '12 at 14:45) sapek sapek's gravatar image
Your answer
If you have an answer to the above question, then use the form below. Otherwise, use the appropriate 'add new comment' button above to post your feedback.
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

Tags:

×148
×5
×3

Asked: Oct 07 '12 at 00:50

Seen: 589 times

Last updated: Oct 07 '12 at 14:50

Plans & prices    Sign up    Why WebFaction?    Contact us    Affiliate program    Support    Legal    Jobs    Blog    Control panel login
Powered by OSQA
© Copyright 2003-2012 Swarma Limited - WebFaction is a service of Swarma Limited