-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.json
59 lines (59 loc) · 15.4 KB
/
package.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{
"name": "simplesmtp",
"description": "Simple SMTP server module to create custom SMTP servers",
"version": "0.3.16",
"author": {
"name": "Andris Reinman"
},
"maintainers": [
{
"name": "andris",
"email": "andris@node.ee"
}
],
"repository": {
"type": "git",
"url": "http://github.com/andris9/simplesmtp.git"
},
"scripts": {
"test": "nodeunit test/"
},
"main": "./lib/smtp",
"licenses": [
{
"type": "MIT",
"url": "http://github.com/andris9/simplesmtp/blob/master/LICENSE"
}
],
"dependencies": {
"rai": "~0.1",
"xoauth2": "~0.1"
},
"devDependencies": {
"nodeunit": "*",
"mailcomposer": "*"
},
"engines": {
"node": ">=0.8.0"
},
"keywords": [
"servers",
"text-based",
"smtp",
"email",
"mail",
"e-mail"
],
"readme": "# simplesmtp\n\nThis is a module to easily create custom SMTP servers and clients - use SMTP as a first class protocol in Node.JS!\n\n[![Build Status](https://secure.travis-ci.org/andris9/simplesmtp.png)](http://travis-ci.org/andris9/simplesmtp)\n[![NPM version](https://badge.fury.io/js/simplesmtp.png)](http://badge.fury.io/js/simplesmtp)\n\n## Version warning!\n\nIf you are using node v0.6, then the last usable version of **simplesmtp** is v0.2.7\n\nCurrent version of simplesmtp is fully supported for Node v0.8+\n\n## Support simplesmtp development\n\n[![Donate to author](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DB26KWR2BQX5W)\n\n## SMTP Server\n\n## Simple SMTP server\n\nFor a simple inbound only, no authentication SMTP server you can use\n\n simplesmtp.createSimpleServer([options], requestListener).listen(port);\n\nExample\n\n simplesmtp.createSimpleServer({SMTPBanner:\"My Server\"}, function(req){\n req.pipe(process.stdout);\n req.accept();\n }).listen(port);\n\nProperties\n\n * **req.from** - From address\n * **req.to** - an array of To addresses\n * **req.host** - hostname reported by the client\n * **req.remodeAddress** - client IP address\n\nMethods\n\n * **req.accept** *([id])* - Accept the message with the selected ID\n * **req.reject** *([message])* - Reject the message with the selected message\n * **req.pipe** *(stream)* - Pipe the incoming data to a writable stream\n\nEvents\n\n * **'data'** *(chunk)* - A chunk (Buffer) of the message.\n * **'end'** - The message has been transferred\n\n\n## Advanced SMTP server\n\n### Usage\n\nCreate a new SMTP server instance with\n\n var smtp = simplesmtp.createServer([options]);\n\nAnd start listening on selected port\n\n smtp.listen(25, [function(err){}]);\n\nSMTP options can include the following:\n\n * **name** - the hostname of the server, will be used for informational messages\n * **debug** - if set to true, print out messages about the connection\n * **timeout** - client timeout in milliseconds, defaults to 60 000 (60 sec.)\n * **secureConnection** - start a server on secure connection\n * **SMTPBanner** - greeting banner that is sent to the client on connection\n * **requireAuthentication** - if set to true, require that the client must authenticate itself\n * **enableAuthentication** - if set to true, client may authenticate itself but don't have to (as opposed to `requireAuthentication` that explicitly requires clients to authenticate themselves)\n * **maxSize** - maximum size of an e-mail in bytes (currently informational only)\n * **credentials** - TLS credentials (`{key:'', cert:'', ca:['']}`) for the server\n * **authMethods** - allowed authentication methods, defaults to `[\"PLAIN\", \"LOGIN\"]`\n * **disableEHLO** - if set to true, support HELO command only\n * **ignoreTLS** - if set to true, allow client do not use STARTTLS\n * **disableDNSValidation** - if set, do not validate sender domains\n\n### Example\n\n var simplesmtp = require(\"simplesmtp\"),\n fs = require(\"fs\");\n\n var smtp = simplesmtp.createServer();\n smtp.listen(25);\n\n smtp.on(\"startData\", function(connection){\n console.log(\"Message from:\", connection.from);\n console.log(\"Message to:\", connection.to);\n connection.saveStream = fs.createWriteStream(\"/tmp/message.txt\");\n });\n\n smtp.on(\"data\", function(connection, chunk){\n connection.saveStream.write(chunk);\n });\n\n smtp.on(\"dataReady\", function(connection, callback){\n connection.saveStream.end();\n console.log(\"Incoming message saved to /tmp/message.txt\");\n callback(null, \"ABC1\"); // ABC1 is the queue id to be advertised to the client\n // callback(new Error(\"Rejected as spam!\")); // reported back to the client\n });\n\n### Events\n\n * **startData** *(connection)* - DATA stream is opened by the client (`connection` is an object with `from`, `to`, `host` and `remoteAddress` properties)\n * **data** *(connection, chunk)* - e-mail data chunk is passed from the client\n * **dataReady** *(connection, callback)* - client is finished passing e-mail data, `callback` returns the queue id to the client\n * **authorizeUser** *(connection, username, password, callback)* - will be emitted if `requireAuthentication` option is set to true. `callback` has two parameters *(err, success)* where `success` is Boolean and should be true, if user is authenticated successfully\n * **validateSender** *(connection, email, callback)* - will be emitted if `validateSender` listener is set up\n * **validateRecipient** *(connection, email, callback)* - will be emitted it `validataRecipients` listener is set up\n * **close** *(connection)* - emitted when the connection to client is closed\n\n## SMTP Client\n\n### Usage\n\nSMTP client can be created with `simplesmtp.connect(port[,host][, options])`\nwhere\n\n * **port** is the port to connect to\n * **host** is the hostname to connect to (defaults to \"localhost\")\n * **options** is an optional options object (see below)\n\n### Connection options\n\nThe following connection options can be used with `simplesmtp.connect`:\n\n * **secureConnection** - use SSL\n * **name** - the name of the client server\n * **auth** - authentication object `{user:\"...\", pass:\"...\"}` or `{XOAuthToken:\"base64data\"}`\n * **ignoreTLS** - ignore server support for STARTTLS\n * **tls** - optional options object for `tls.connect`, also applies to STARTTLS. For example `rejectUnauthorized` is set to `false` by default. You can override this option by setting `tls: {rejectUnauthorized: true}`\n * **debug** - output client and server messages to console\n * **logFile** - optional filename where communication with remote server has to be logged\n * **instanceId** - unique instance id for debugging (will be output console with the messages)\n * **localAddress** - local interface to bind to for network connections (needs Node.js >= 0.11.3 for working with tls)\n * **greetingTimeout** (defaults to 10000) - Time to wait in ms until greeting message is received from the server\n * **connectionTimeout** (system default if not set) - Time to wait in ms until the socket is opened to the server\n * **rejectUnathorized** (defaults to false) - if set to true accepts only valid server certificates. You can override this option with the `tls` option, this is just a shorthand\n * **dsn** - An object with methods `success`, `failure` and `delay`. If any of these are set to true, DSN will be used\n\n### Connection events\n\nOnce a connection is set up the following events can be listened to:\n\n * **'idle'** - the connection to the SMTP server has been successfully set up and the client is waiting for an envelope\n * **'message'** - the envelope is passed successfully to the server and a message stream can be started\n * **'ready'** `(success)` - the message was sent\n * **'rcptFailed'** `(addresses)` - not all recipients were accepted (invalid addresses are included as an array)\n * **'error'** `(err, stage)` - An error occurred. The connection is closed and an 'end' event is emitted shortly. Second argument indicates on which SMTP session stage an error occured.\n * **'end'** - connection to the client is closed\n\n### Sending an envelope\n\nWhen an `'idle'` event is emitted, an envelope object can be sent to the server.\nThis includes a string `from` and an array of strings `to` property.\n\nEnvelope can be sent with `client.useEnvelope(envelope)`\n\n // run only once as 'idle' is emitted again after message delivery\n client.once(\"idle\", function(){\n client.useEnvelope({\n from: \"me@example.com\",\n to: [\"receiver1@example.com\", \"receiver2@example.com\"]\n });\n });\n\nThe `to` part of the envelope includes **all** recipients from `To:`, `Cc:` and `Bcc:` fields.\n\nIf setting the envelope up fails, an error is emitted. If only some (not all)\nrecipients are not accepted, the mail can still be sent but an `rcptFailed`\nevent is emitted.\n\n client.on(\"rcptFailed\", function(addresses){\n console.log(\"The following addresses were rejected: \", addresses);\n });\n\nIf the envelope is set up correctly a `'message'` event is emitted.\n\n### Sending a message\n\nWhen `'message'` event is emitted, it is possible to send mail. To do this\nyou can pipe directly a message source (for example an .eml file) to the client\nor alternatively you can send the message with `client.write` calls (you also\nneed to call `client.end()` once the message is completed.\n\nIf you are piping a stream to the client, do not leave the `'end'` event out,\nthis is needed to complete the message sequence by the client.\n\n client.on(\"message\", function(){\n fs.createReadStream(\"test.eml\").pipe(client);\n });\n\nOnce the message is delivered a `'ready'` event is emitted. The event has an\nparameter which indicates if the message was transmitted( (true) or not (false)\nand another which includes the last received data from the server.\n\n client.on(\"ready\", function(success, response){\n if(success){\n console.log(\"The message was transmitted successfully with \"+response);\n }\n });\n\n### XOAUTH\n\n**simplesmtp** supports [XOAUTH2 and XOAUTH](https://developers.google.com/google-apps/gmail/oauth_protocol) authentication.\n\n#### XOAUTH2\n\nTo use this feature you can set `XOAuth2` param as an `auth` option\n\n var mailOptions = {\n ...,\n auth:{\n XOAuth2: {\n user: \"example.user@gmail.com\",\n clientId: \"8819981768.apps.googleusercontent.com\",\n clientSecret: \"{client_secret}\",\n refreshToken: \"1/xEoDL4iW3cxlI7yDbSRFYNG01kVKM2C-259HOF2aQbI\",\n accessToken: \"vF9dft4qmTc2Nvb3RlckBhdHRhdmlzdGEuY29tCg==\",\n timeout: 3600\n }\n }\n }\n\n`accessToken` and `timeout` values are optional. If login fails a new access token is generated automatically.\n\n#### XOAUTH\n\nTo use this feature you can set `XOAuthToken` param as an `auth` option\n\n var mailOptions = {\n ...,\n auth:{\n XOAuthToken: \"R0VUIGh0dHBzOi8vbWFpbC5nb29....\"\n }\n }\n\nAlternatively it is also possible to use XOAuthToken generators (supported by Nodemailer) - this\nneeds to be an object with a mandatory method `generate` that takes a callback function for\ngenerating a XOAUTH token string. This is better for generating tokens only when needed -\nthere is no need to calculate unique token for every e-mail request, since a lot of these\nmight share the same connection and thus the cleint needs not to re-authenticate itself\nwith another token.\n\n var XOGen = {\n token: \"abc\",\n generate: function(callback){\n if(1 != 1){\n return callback(new Error(\"Tokens can't be generated in strange environments\"));\n }\n callback(null, new Buffer(this.token, \"utf-8\").toString(\"base64\"));\n }\n }\n\n var mailOptions = {\n ...,\n auth:{\n XOAuthToken: XOGen\n }\n }\n\n### Error types\n\nEmitted errors include the reason for failing in the `name` property\n\n * **UnknowAuthError** - the client tried to authenticate but the method was not supported\n * **AuthError** - the username/password used were rejected\n * **TLSError** - STARTTLS failed\n * **SenderError** - the sender e-mail address was rejected\n * **RecipientError** - all recipients were rejected (if only some of the recipients are rejected, a `'rcptFailed'` event is raised instead\n\nThere's also an additional property in the error object called `data` that includes\nthe last response received from the server (if available for the current error type).\n\n### About reusing the connection\n\nYou can reuse the same connection several times but you can't send a mail\nthrough the same connection concurrently. So if you catch and `'idle'` event\nlock the connection to a message process and unlock after `'ready'`.\n\nOn `'error'` events you should reschedule the message and on `'end'` events\nyou should recreate the connection.\n\n### Closing the client\n\nBy default the client tries to keep the connection up. If you want to close it,\nrun `client.quit()` - this sends a `QUIT` command to the server and closes the\nconnection\n\n client.quit();\n\n## SMTP Client Connection pool\n\n**simplesmtp** has the option for connection pooling if you want to reuse a bulk\nof connections.\n\n### Usage\n\nCreate a connection pool of SMTP clients with\n\n simplesmtp.createClientPool(port[,host][, options])\n\nwhere\n\n * **port** is the port to connect to\n * **host** is the hostname to connect to (defaults to \"localhost\")\n * **options** is an optional options object (see below)\n\n### Connection options\n\nThe following connection options can be used with `simplesmtp.connect`:\n\n * **secureConnection** - use SSL\n * **name** - the name of the client server\n * **auth** - authentication object `{user:\"...\", pass:\"...\"}` or `{XOAuthToken:\"base64data\"}`\n * **ignoreTLS** - ignore server support for STARTTLS\n * **debug** - output client and server messages to console\n * **logFile** - optional filename where communication with remote server has to be logged\n * **maxConnections** - how many connections to keep in the pool (defaults to 5)\n * **localAddress** - local interface to bind to for network connections (needs Node.js >= 0.11.3 for working with tls)\n * **maxMessages** - limit the count of messages to send through a single connection (no limit by default)\n\n### Send an e-mail\n\nE-mails can be sent through the pool with\n\n pool.sendMail(mail[, callback])\n\nwhere\n\n * **mail** is a [MailComposer](https://github.com/andris9/mailcomposer) compatible object\n * **callback** `(error, responseObj)` - is the callback function to run after the message is delivered or an error occured. `responseObj` may include `failedRecipients` which is an array with e-mail addresses that were rejected and `message` which is the last response from the server.\n\n### Errors\n\nIn addition to SMTP client errors another error name is used\n\n * **DeliveryError** - used if the message was not accepted by the SMTP server\n\n## License\n\n**MIT**\n\n",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/andris9/simplesmtp/issues"
},
"homepage": "https://github.com/andris9/simplesmtp",
"_id": "simplesmtp@0.3.16",
"dist": {
"shasum": "c82ab64b957a5f979b10b96787094e3612877814"
},
"_from": "simplesmtp@~0.2 || ~0.3",
"_resolved": "https://registry.npmjs.org/simplesmtp/-/simplesmtp-0.3.16.tgz"
}