New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

emailjs-smtp-client

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

emailjs-smtp-client - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

.babelrc

54

package.json
{
"name": "emailjs-smtp-client",
"version": "1.0.0",
"version": "2.0.0",
"homepage": "https://github.com/emailjs/emailjs-smtp-client",
"description": "SMTP Client allows you to connect to and stream data to a SMTP server in the browser.",
"description": "SMTP Client allows you to connect to an SMTP server in JS.",
"author": "Andris Reinman <andris@kreata.ee>",

@@ -12,4 +12,8 @@ "keywords": [

"scripts": {
"pretest": "dir=$(pwd) && cd node_modules/node-forge/ && npm install && npm run minify && cd $dir",
"test": "grunt"
"build": "./scripts/build.sh",
"release": "./scripts/release.sh",
"lint": "$(npm bin)/standard",
"test": "npm run lint && npm run unit && npm run integration",
"unit": "$(npm bin)/mocha './src/*-unit.js' --reporter spec --require babel-register testutils.js",
"integration": "$(npm bin)/mocha './src/*-integration.js' --reporter spec --require babel-register testutils.js"
},

@@ -20,22 +24,34 @@ "repository": {

},
"main": "src/emailjs-smtp-client",
"main": "dist/index",
"dependencies": {
"emailjs-stringencoding": "^1.0.1",
"emailjs-tcp-socket": "^1.0.1"
"emailjs-base64": "^1.1.4",
"emailjs-tcp-socket": "^2.0.0",
"text-encoding": "^0.6.4"
},
"devDependencies": {
"chai": "^3.4.1",
"grunt": "^0.4.5",
"grunt-contrib-clean": "^0.7.0",
"grunt-contrib-connect": "^0.11.2",
"grunt-contrib-copy": "^0.8.2",
"grunt-contrib-jshint": "^0.11.3",
"grunt-contrib-watch": "^0.6.1",
"grunt-mocha-phantomjs": "^2.0.1",
"grunt-mocha-test": "^0.12.7",
"mocha": "^2.3.4",
"requirejs": "^2.1.22",
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-register": "^6.26.0",
"chai": "^4.1.2",
"mocha": "^5.0.0",
"pre-commit": "^1.2.2",
"simplesmtp": "^0.3.35",
"sinon": "^1.17.2"
"sinon": "^4.2.2",
"standard": "^10.0.3"
},
"standard": {
"globals": [
"describe",
"it",
"before",
"beforeEach",
"afterEach",
"after",
"expect",
"sinon"
],
"ignore": [
"dist"
]
}
}
# SMTP Client
[![Greenkeeper badge](https://badges.greenkeeper.io/emailjs/emailjs-smtp-client.svg)](https://greenkeeper.io/) [![Build Status](https://travis-ci.org/emailjs/emailjs-smtp-client.png?branch=master)](https://travis-ci.org/emailjs/emailjs-smtp-client) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) [![ES6+](https://camo.githubusercontent.com/567e52200713e0f0c05a5238d91e1d096292b338/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f65732d362b2d627269676874677265656e2e737667)](https://kangax.github.io/compat-table/es6/)
SMTP Client allows you to connect to and stream data to a SMTP server in the browser.
[![Build Status](https://travis-ci.org/emailjs/emailjs-smtp-client.png?branch=master)](https://travis-ci.org/emailjs/emailjs-smtp-client)
## API
## StringEncoding API
Installation: `npm install emailjs-smtp-client`
This module requires `TextEncoder` and `TextDecoder` to exist as part of the StringEncoding API (see: [MDN](https://developer.mozilla.org/en-US/docs/WebAPI/Encoding_API) [whatwg.org](http://encoding.spec.whatwg.org/#api)). Firefox 19+ is basically the only browser that supports this at the time of writing, while [Chromium in canary, not stable](https://code.google.com/p/chromium/issues/detail?id=243354). Luckily, [there is a polyfill](https://github.com/emailjs/emailjs-stringencoding)!
Depending on your browser, you might need [this polyfill for ArrayBuffer #slice](https://github.com/ttaubert/node-arraybuffer-slice), e.g. phantomjs.
## TCPSocket API
There is a [shim](https://github.com/emailjs/emailjs-tcp-socket) that brings [Mozilla-flavored](https://developer.mozilla.org/en-US/docs/WebAPI/TCP_Socket) version of the [Raw Socket API](http://www.w3.org/TR/raw-sockets/) to other platforms.
If you are on a platform that uses forge instead of a native TLS implementation (e.g. chrome.socket), you have to set the .oncert(pemEncodedCertificate) handler that passes the TLS certificate that the server presents. It can be used on a trust-on-first-use basis for subsequent connection.
If forge is used to handle TLS traffic, you may choose to handle the TLS-related load in a Web Worker. Please use tlsWorkerPath to point to `tcp-socket-tls-worker.js`!
Please take a look at the [tcp-socket documentation](https://github.com/emailjs/emailjs-tcp-socket) for more information!
## Installation
### [npm](https://www.npmjs.org/):
npm install --save emailjs-smtp-client
## Quirks
* `STARTTLS` is currently not supported
* Only `PLAIN`, `USER` and `XOAUTH2` authentication mechanisms are supported. `XOAUTH2` expects a ready to use access token, no tokens are generated automatically.
## Usage
### AMD
Require [emailjs-smtp-client.js](src/emailjs-smtp-client.js) as `emailjs-smtp-client`
### Global context
Include files [emailjs-smtp-client-response-parser.js](src/emailjs-smtp-client-response-parser.js) and [emailjs-smtp-client.js](src/emailjs-smtp-client.js) on the page.
```html
<script src="emailjs-smtp-client-response-parser.js"></script>
<script src="emailjs-smtp-client.js"></script>
```
This exposes global variable `emailjs-smtp-client`
## API
Create `SmtpClient` object with:
```javascript
import SmtpClient from 'emailjs-smtp-client'
var client = new SmtpClient(host, port, options)

@@ -61,5 +20,5 @@ ```

* **host** is the hostname to connect to (defaults to "localhost")
* **port** is the port to connect to
* **options** is an optional options object (see below)
* **host** is the hostname to connect to (defaults to "localhost")
* **port** is the port to connect to
* **options** is an optional options object (see below)

@@ -70,16 +29,14 @@ ## Connection options

* **useSecureTransport** *Boolean* Set to true, to use encrypted connection
* **name** *String* Client hostname for introducing itself to the server
* **auth** *Object* Authentication options. Depends on the preferred authentication method
* **user** is the username for the user (also applies to OAuth2)
* **pass** is the password for the user if plain auth is used
* **xoauth2** is the OAuth2 access token to be used instead of password. If both password and xoauth2 token are set, the token is preferred.
* **useSecureTransport** *Boolean* Set to true, to use encrypted connection
* **name** *String* Client hostname for introducing itself to the server
* **auth** *Object* Authentication options. Depends on the preferred authentication method
* **user** is the username for the user (also applies to OAuth2)
* **pass** is the password for the user if plain auth is used
* **xoauth2** is the OAuth2 access token to be used instead of password. If both password and xoauth2 token are set, the token is preferred.
* **authMethod** *String* Force specific authentication method (eg. `"PLAIN"` for using `AUTH PLAIN` or `"XOAUTH2"` for `AUTH XOAUTH2`)
* **ca** (optional) (only in conjunction with this [TCPSocket shim](https://github.com/emailjs/emailjs-tcp-socket)) if you use TLS with forge, pin a PEM-encoded certificate as a string. Please refer to the [tcp-socket documentation](https://github.com/emailjs/emailjs-tcp-socket) for more information!
* **tlsWorkerPath** (optional) (only in conjunction with this [TCPSocket shim](https://github.com/emailjs/emailjs-tcp-socket)) if you use TLS with forge, this path indicates where the file for the TLS Web Worker is located. Please refer to the [tcp-socket documentation](https://github.com/emailjs/emailjs-tcp-socket) for more information!
* **disableEscaping** *Boolean* If set to true, do not escape dots on the beginning of the lines
* **logLength** *Number* How many messages between the client and the server to log. Set to false to disable logging. Defaults to 6
* **ignoreTLS** – if set to true, do not issue STARTTLS even if the server supports it
* **requireTLS** – if set to true, always use STARTTLS before authentication even if the host does not advertise it. If STARTTLS fails, do not try to authenticate the user
* **lmtp** - if set to true use LMTP commands instead of SMTP commands
* **ca** (optional) (only in conjunction with this [TCPSocket shim](https://github.com/emailjs/emailjs-tcp-socket)) if you use TLS with forge, pin a PEM-encoded certificate as a string. Please refer to the [tcp-socket documentation](https://github.com/emailjs/emailjs-tcp-socket) for more information!
* **disableEscaping** *Boolean* If set to true, do not escape dots on the beginning of the lines
* **ignoreTLS** – if set to true, do not issue STARTTLS even if the server supports it
* **requireTLS** – if set to true, always use STARTTLS before authentication even if the host does not advertise it. If STARTTLS fails, do not try to authenticate the user
* **lmtp** - if set to true use LMTP commands instead of SMTP commands

@@ -94,7 +51,7 @@ Default STARTTLS support is opportunistic – if the server advertises STARTTLS in EHLO response, the client tries to use it. If STARTTLS is not advertised, the clients sends passwords in the plain. You can use `ignoreTLS` and `requireTLS` to change this behavior by explicitly enabling or disabling STARTTLS usage.

var config = {
auth: {
user: 'username',
xoauth2: 'access_token'
auth: {
user: 'username',
xoauth2: 'access_token'
}
};
}
```

@@ -108,7 +65,7 @@

* **onidle** - the connection to the SMTP server has been successfully set up and the client is waiting for an envelope. **NB!** this event is emitted multiple times - if an e-mail has been sent and the client has nothing to do, `onidle` is emitted again.
* **onready** `(failedRecipients)` - the envelope is passed successfully to the server and a message stream can be started. The argument is an array of e-mail addresses not accepted as recipients by the server. If none of the recipient addresses is accepted, `onerror` is emitted instead.
* **ondone** `(success)` - the message was sent
* **onerror** `(err)` - An error occurred. The connection will be closed shortly afterwards, so expect an `onclose` event as well
* **onclose** `(isError)` - connection to the client is closed. If `isError` is true, the connection is closed because of an error
* **onidle** - the connection to the SMTP server has been successfully set up and the client is waiting for an envelope. **NB!** this event is emitted multiple times - if an e-mail has been sent and the client has nothing to do, `onidle` is emitted again.
* **onready** `(failedRecipients)` - the envelope is passed successfully to the server and a message stream can be started. The argument is an array of e-mail addresses not accepted as recipients by the server. If none of the recipient addresses is accepted, `onerror` is emitted instead.
* **ondone** `(success)` - the message was sent
* **onerror** `(err)` - An error occurred. The connection will be closed shortly afterwards, so expect an `onclose` event as well
* **onclose** `(isError)` - connection to the client is closed. If `isError` is true, the connection is closed because of an error

@@ -119,5 +76,5 @@ Example:

client.onidle = function(){
console.log("Connection has been established");
// this event will be called again once a message has been sent
// so do not just initiate a new message here, as infinite loops might occur
console.log("Connection has been established");
// this event will be called again once a message has been sent
// so do not just initiate a new message here, as infinite loops might occur
}

@@ -138,10 +95,9 @@ ```

client.onidle = function(){
if(alreadySending){
return;
}
alreadySending = true;
client.useEnvelope({
from: "me@example.com",
to: ["receiver1@example.com", "receiver2@example.com"]
});
if(alreadySending) return
alreadySending = true
client.useEnvelope({
from: "me@example.com",
to: ["receiver1@example.com", "receiver2@example.com"]
})
}

@@ -159,6 +115,6 @@ ```

client.onready = function(failedRecipients){
if(failedRecipients.length){
console.log("The following addresses were rejected: ", failedRecipients);
}
// start transfering the e-mail
if(failedRecipients.length){
console.log("The following addresses were rejected: ", failedRecipients)
}
// start transfering the e-mail
}

@@ -179,6 +135,6 @@ ```

client.onready = function(){
client.send("Subject: test\r\n");
client.send("\r\n");
client.send("Message body");
client.end();
client.send("Subject: test\r\n");
client.send("\r\n");
client.send("Message body");
client.end();
}

@@ -190,18 +146,7 @@ ```

```
client.ondone = function(success){
if(success){
console.log("The message was transmitted successfully with "+response);
}
}
```
## Logging
At any time you can access the traffic log between the client and the server from the `client.log` array.
```javascript
client.ondone = function(success){
// show the last message
console.log(client.log.slice(-1));
if(success){
console.log("The message was transmitted successfully");
}
}

@@ -216,33 +161,27 @@ ```

## Get your hands dirty
## Quirks
git clone git@github.com:whiteout-io/smtpclient.git
cd smtpclient
npm install && npm test
* `STARTTLS` is currently not supported
* Only `PLAIN`, `USER` and `XOAUTH2` authentication mechanisms are supported. `XOAUTH2` expects a ready to use access token, no tokens are generated automatically.
To run the integration tests against a local smtp server
grunt smtp
add the test folder as a chrome app (chrome settings -> extensions -> check 'developer mode' -> load unpacked extension)
## License
Copyright (c) 2013 Andris Reinman
Copyright (c) 2013 Andris Reinman
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc