postmaster

所属分类:Email服务器
开发工具:CoffeeScript
文件大小:19KB
下载次数:0
上传日期:2012-04-28 17:24:31
上 传 者sh-1993
说明:  一个小型SMTP服务器,在HTTP API中存储和公开电子邮件以进行测试
(A tiny SMTP server that stores and exposes your emails in an HTTP API for testing)

文件列表:
.travis.yml (52, 2012-04-29)
Cakefile (519, 2012-04-29)
bin (0, 2012-04-29)
bin\postmaster (49, 2012-04-29)
lib (0, 2012-04-29)
lib\api.js (1035, 2012-04-29)
lib\command.js (658, 2012-04-29)
lib\parser.js (3231, 2012-04-29)
lib\postmaster.js (244, 2012-04-29)
lib\server.js (4418, 2012-04-29)
lib\store.js (756, 2012-04-29)
package.json (659, 2012-04-29)
src (0, 2012-04-29)
src\api.coffee (743, 2012-04-29)
src\command.coffee (562, 2012-04-29)
src\parser.coffee (2329, 2012-04-29)
src\postmaster.coffee (209, 2012-04-29)
src\server.coffee (5217, 2012-04-29)
src\store.coffee (468, 2012-04-29)
test (0, 2012-04-29)
test\api_test.coffee (2256, 2012-04-29)
test\integration_test.coffee (4678, 2012-04-29)
test\parser_test.coffee (5117, 2012-04-29)
test\server_handle_test.coffee (3918, 2012-04-29)
test\server_test.coffee (4374, 2012-04-29)
test\store_test.coffee (1241, 2012-04-29)

# Postmaster [![Build Status](https://secure.travis-ci.org/jamierumbelow/postmaster.png?branch=master)](http://travis-ci.org/jamierumbelow/postmaster) Postmaster is a tiny SMTP server that stores all messages in memory and exposes an HTTP API to retrieve them later. This makes it really easy to test the headers and the content of your emails. ## Installation Install Postmaster with [npm](http://npmjs.org/): $ npm install -g postmaster You can then run Postmaster with the `postmaster` command, which should be in your path: $ postmaster Postmaster reporting for duty on localhost:5666 (HTTP - localhost:5667) Change the bound hostname and port with the `-l` and `-p` flags, respectively: $ postmaster -p 4432 -l 127.0.0.1 Postmaster reporting for duty on 127.0.0.1:4432 (HTTP - 127.0.0.1:4433) ## HTTP API The HTTP API will open up on the next port from the Postmaster port. Sending an `HTTP GET` request to `/emails` will return a JSON array of the parsed email and associated headers. $ curl http://localhost:5667/emails {"1":{"headers":{"User-Agent":"CodeIgniter","Date":"Sat, 28 Apr 2012 17:49:55 +0100","From":"","Return-Path":"","To":"another@example.com","Subject":"=?utf-8?Q?Some_random_email?=","Reply-To":"\"test@example.com\" ","X-Sender":"test@example.com","X-Mailer":"CodeIgniter","X-Priority":"3 (Normal)","Message-ID":"<4f9c1fb3d6878@example.com>","Mime-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"8bit"},"body":"Oh yeah","html":false,"subject":"Some random email","from":"test@example.com","to":["another@example.com"]}} Piped through a JSON prettifier, the output looks like this: $ curl -s http://localhost:5667/emails | python -mjson.tool { "1": { "body": "Oh yeah", "from": "test@example.com", "headers": { "Content-Transfer-Encoding": "8bit", "Content-Type": "text/plain; charset=utf-8", "Date": "Sat, 28 Apr 2012 17:49:55 +0100", "From": "", "Message-ID": "<4f9c1fb3d6878@example.com>", "Mime-Version": "1.0", "Reply-To": "\"test@example.com\" ", "Return-Path": "", "Subject": "=?utf-8?Q?Some_random_email?=", "To": "jamie@jamierumbelow.net", "User-Agent": "CodeIgniter", "X-Mailer": "CodeIgniter", "X-Priority": "3 (Normal)", "X-Sender": "test@example.com" }, "html": false, "subject": "Some random email", "to": [ "jamie@jamierumbelow.net" ] } } The email's original headers and body are stored and returned, alongside the parsed subject, whether or not the email is HTML, and the from/to address(es). ## PHP Example Assuming we've got an application sending out an email when the user is registered, and we want to test it, we can boot up Postmaster, run the register method and check the HTTP API very easily: register('test_email@domain.com', 'test_password'); // Grab our emails $curl = curl_init('http://localhost:5667/emails'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); $json = curl_exec($curl); curl_close(); $emails = (array)json_decode($json); // Check that the email is what it's supposed to be! $this->assertEqual($emails['1']->from, 'hello@myapp.com'); $this->assertEqual($emails['1']->to, 'test_email@domain.com'); $this->assertEqual($emails['1']->subject, 'MyApp - Welcome to MyApp!'); // Kill the process pclose($postmaster); } } ## Development / Tests Grab the most recent copy of the codebase from GitHub: $ git clone git://github.com/jamierumbelow/postmaster.git postmaster Install yer modules: $ npm install And run the test suite with cake! $ cake test If you're developing locally and would like an easy way to rebuild the source, run `cake build`: $ cake build && ./bin/postmaster

近期下载者

相关文件


收藏者