|
| 1 | +# Postman |
| 2 | + |
| 3 | +Postman is a simple IMAP idling daemon which will monitor the specified mailbox for incoming email messages and delivery them to a postback endpoint. |
| 4 | + |
| 5 | +It works incredibly well for applications which need to process incoming email messages as they arrive. ie: helpdesk apps. |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +Postman is written in Go. This means it should run under Windows, Linux, FreeBSD and OSX. |
| 10 | + |
| 11 | +### Binary |
| 12 | + |
| 13 | +Installation is very easy. Simply download the appropiate version for your platform from the [releases](https://github.com/etrepat/postman/releases) page. Once downloaded it can be run from anywhere. You don't need to install it into a global location. This works well for shared hosts and other systems where you may not have a privileged account. |
| 14 | + |
| 15 | +If you want to install it globally, I'd recommend somewherewhich already is in your user's path. For example: `/usr/local/bin` may be a good candidate. |
| 16 | + |
| 17 | +*The Postman executable has no external dependencies* |
| 18 | + |
| 19 | +### Building from source |
| 20 | + |
| 21 | +As with any go package building from source is pretty easy. First: |
| 22 | + |
| 23 | + go get github.com/etrepat/postman |
| 24 | + |
| 25 | +Then build: |
| 26 | + |
| 27 | + cd /path/to/postman |
| 28 | + go build -o postman main.go |
| 29 | + |
| 30 | +Now you should have a `postman` binary available in the project folder. It's already ready to run! |
| 31 | + |
| 32 | +## Usage |
| 33 | + |
| 34 | +Postman is a rather simple tool. The first thing you should do is run `postman -h` and see the available parameters. You'll immediately see that the options are pretty self explanatory and basically involve 3 areas: connection options (host, port, user, ...), mailbox selection (which IMAP mailbox to monitor) and operation mode. |
| 35 | + |
| 36 | + postman -h imap.gmail.com --ssl -U <username> -P <password> --postback-url=<receiving host> |
| 37 | + |
| 38 | +### Connection management parameters |
| 39 | + |
| 40 | +#### -h, --host |
| 41 | + |
| 42 | +Specify the hostname or ip address of IMAP server. |
| 43 | + |
| 44 | +#### -p, --port |
| 45 | + |
| 46 | +IMAP server port number. It will default 143 or 993 if ssl is enforced. |
| 47 | + |
| 48 | +#### --ssl |
| 49 | + |
| 50 | +Enforce a SSL connection. Will default to true if port is set to *993*. |
| 51 | + |
| 52 | +#### -U, --user |
| 53 | + |
| 54 | +The IMAP server login username. |
| 55 | + |
| 56 | +#### -P, --password |
| 57 | + |
| 58 | +The IMAP server login password. |
| 59 | + |
| 60 | +### Mailbox selection and mode of operation parameters |
| 61 | + |
| 62 | +#### -b, --mailbox |
| 63 | + |
| 64 | +The IMAP mailbox name to start monitoring on. Will default to *INBOX* if not given. |
| 65 | + |
| 66 | +#### -m, --mode |
| 67 | + |
| 68 | +Sets the daemon mode of operation. Must be one of: `logger`, `postback`. |
| 69 | + |
| 70 | +The `logger` mode is mainly for debugging/testing purposes and it will "spit out" the raw email message data into stdout whenever a new mail arrives at the specified IMAP mailbox. |
| 71 | + |
| 72 | +In `postback` mode, Postman will grab the raw email message data and perform a **POST** request to an endpoint of your choosing. This mode allows for the following additional parameters: |
| 73 | + |
| 74 | +* **--postback-url**: URL to POST incoming raw email message data. By default all data will be sent in the post body with a *text/plain* content-type. |
| 75 | +* **--encode**: Will perform the POST request as if it were form data (x-form-urlencoded) wrapping the raw email message in a post parameter. |
| 76 | +* **--parname**: Sets the parameter name to be used when `--encode` is set. Defaults to **message**. |
| 77 | + |
| 78 | +## Receiving email data in Rails |
| 79 | + |
| 80 | +This utility was developed as part of a Rails application. You should take into consideration the following points when using the *postback* functionality in a Rails app: |
| 81 | + |
| 82 | +* First, you should disable forgery protection on the receiving controller action. |
| 83 | +* If you need to use an authentication token, you may add it to the `postback-url` as a query parameter. You may use ENV vars for that. |
| 84 | +* Doing something like `raw_email = request.body.read` in the controller will get you the raw email message data as a string. You can then use the awesome [mail gem](https://github.com/mikel/mail) like this: `mail = Mail.new(raw_email)` to parse the email message and retrieve all the information you need. |
| 85 | + |
| 86 | +## Using with Upstart |
| 87 | + |
| 88 | +To avoid service interruptions, I'd recommend using Postman in combination with some process monitoring tool. For most of my use cases though I personally find that [Upstart](http://http://upstart.ubuntu.com/) is just enough. Here's an sample init script for Postman which may be used as an starting point: |
| 89 | + |
| 90 | +```sh |
| 91 | +start on runlevel [2345] |
| 92 | +stop on runlevel [016] |
| 93 | + |
| 94 | +respawn |
| 95 | +respawn limit 10 90 |
| 96 | + |
| 97 | +exec su - <user> -c 'cd /home/<user>/sites/<my-awesome-app>; ./bin/postman -h imap.gmail.com --ssl -U $SMTP_USERNAME -P $SMTP_PASSWD -m postback --postback-url=$POSTMAN_DELIVERY_URL >> /var/log/<my-awesome-app>/postman.log 2>&1' |
| 98 | +``` |
| 99 | + |
| 100 | +## Contributing |
| 101 | + |
| 102 | +Thinking of contributing? Maybe you've found some nasty bug? That's great news! |
| 103 | + |
| 104 | +1. Fork & clone the project: `git clone [email protected]:your-username/postman.git`. |
| 105 | +2. Create your bugfix/feature branch and code away your changes. (git checkout -b my-new-feature). |
| 106 | +4. Push to your fork. |
| 107 | +5. Submit new a pull request. |
| 108 | + |
| 109 | +## License |
| 110 | + |
| 111 | +Postman is licensed under the terms of the [MIT License](http://opensource.org/licenses/MIT) |
| 112 | +(See LICENSE file for details). |
| 113 | + |
| 114 | +--- |
| 115 | + |
| 116 | +Coded by [Estanislau Trepat (etrepat)](http://etrepat.com). I'm also |
| 117 | +[@etrepat](http://twitter.com/etrepat) on twitter. |
0 commit comments