开发者

autostorage email attachment file

开发者 https://www.devze.com 2023-04-08 04:55 出处:网络
I was recently asked by my boss to create... something i find nearly impossible without human intervention

I was recently asked by my boss to create... something i find nearly impossible without human intervention

The thing is, to have our users send a xml with some data via email, but my boss wants it to

  1. That the attached file be stored on a specific folder on a specific server whenever a new email arrives with the attachment
  2. The process will verify that there's a attached file on the email and thats its correct, meaning that it开发者_开发技巧s xml structure is as we asked it and has all the data stored on it
  3. Some of the xml file data be stored on a database (filename, file path, main id) for it to be searched on a little app which displays the xml data and so be able to download a copy of the file

My main problem is, having this process that keeps on cheking new received mails, retrieves the attachments, checks it and store it, i don't know if its possible, or where to start. For once, the email server needs to have some kind of programability processes, but still, looks like the one in charge of our mail server doesn't have any idea if there's something like that.

Any one can give me an idea on where to start with this?

I suggested we had a upload option on our main webpage, and we will have it, but they really want the email option and that all the process its automated


There are a couple of ways to do this. I would start by looking into programatically retrieving the emails via IMAP or POP. This seems like the approach with the least amount of friction involved for you. The person in charge of your email server could just set you up an account that all the messages are forwarded into.

Alternatively you can write something to forward all of the emails to another mail server and use that to pipe the emails into a script or have it forward to a service like cloudmailin.com (which can also send the attachments to S3) so that you can obtain the message programatically.

Once you have the message you then just need to parse out the attachment and copy it over to the folder that you need.


If you have shell access on the mail server, you could use Procmail. It (or whatever you have in your .forward or equivalent) will be fired with each incoming message as its standard input. If not all incoming messages are interesting, having Procmail as a wrapper would certainly make sense. Anyway, the task to validate and detach the incoming attachment is then "just a simple matter of programming", but I hope this should at least be enough to get you started.

:0B
* ^Content-type: application/x-perimental-xml or what have you
| validate-and-store-and-extract-some-data-to-sql

You could certainly make it more elaborate than this (and most likely you will have to) but this essential recipe is not very complicated.

... Your "almost impossible" characterization sounds like you're on Windows (oops, sorry, couldn't resist) but perhaps your mail server is a Unix server nevertheless.

0

精彩评论

暂无评论...
验证码 换一张
取 消