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

emailjs

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

emailjs - npm Package Compare versions

Comparing version 2.2.0 to 3.0.0

email.ts

103

package.json
{
"name": "emailjs",
"description": "send text/html emails and attachments (files, streams and strings) from node.js to any smtp server",
"version": "2.2.0",
"author": "eleith",
"contributors": [
"izuzak",
"Hiverness",
"mscdex",
"jimmybergman",
"zackschuster"
],
"repository": {
"type": "git",
"url": "http://github.com/eleith/emailjs.git"
},
"dependencies": {
"addressparser": "^0.3.2",
"emailjs-mime-codec": "^2.0.7"
},
"devDependencies": {
"chai": "^4.1.2",
"eslint": "^4.19.1",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-mocha": "^5.0.0",
"eslint-plugin-prettier": "^2.6.0",
"mailparser": "^2.2.0",
"mocha": "^5.2.0",
"prettier": "^1.13.5",
"smtp-server": "^3.4.6"
},
"engine": [
"node >= 6"
],
"main": "email.js",
"scripts": {
"test": "mocha -R spec"
},
"license": "MIT",
"prettier": {
"singleQuote": true,
"trailingComma": "es5",
"useTabs": true
}
"name": "emailjs",
"description": "send text/html emails and attachments (files, streams and strings) from node.js to any smtp server",
"version": "3.0.0",
"author": "eleith",
"contributors": [
"izuzak",
"Hiverness",
"mscdex",
"jimmybergman",
"zackschuster"
],
"repository": {
"type": "git",
"url": "http://github.com/eleith/emailjs.git"
},
"type": "module",
"devDependencies": {
"@ledge/configs": "23.0.0",
"@rollup/plugin-commonjs": "12.0.0",
"@rollup/plugin-node-resolve": "8.0.0",
"@rollup/plugin-typescript": "4.1.2",
"@types/mailparser": "2.7.3",
"@types/smtp-server": "3.5.4",
"@typescript-eslint/eslint-plugin": "3.0.1",
"@typescript-eslint/parser": "3.0.1",
"addressparser": "1.0.1",
"ava": "3.8.2",
"emailjs-mime-codec": "2.0.9",
"eslint": "7.1.0",
"eslint-config-prettier": "6.11.0",
"eslint-plugin-prettier": "3.1.3",
"mailparser": "2.7.7",
"prettier": "2.0.5",
"rollup": "2.10.9",
"smtp-server": "3.6.0",
"ts-node": "8.10.1",
"tslib": "2.0.0",
"typescript": "3.9.3"
},
"engine": [
"node >= 10"
],
"files": [
"email.ts",
"smtp",
"rollup"
],
"main": "./rollup/email.cjs",
"types": "./email.ts",
"exports": {
"import": "./rollup/email.mjs",
"require": "./rollup/email.cjs"
},
"scripts": {
"build": "rollup -c rollup.config.ts",
"lint": "eslint *.ts \"+(smtp|test)/*.ts\"",
"test": "ava --serial",
"test-cjs": "npm run build && npm run test -- --node-arguments='--title=cjs'"
},
"license": "MIT"
}

@@ -1,2 +0,2 @@

# emailjs [![Build Status](https://secure.travis-ci.org/eleith/emailjs.png)](http://travis-ci.org/eleith/emailjs)
# emailjs [![Test Status](https://github.com/eleith/emailjs/workflows/.github/workflows/test.yml/badge.svg)](https://github.com/eleith/emailjs/actions?query=workflow%3A.github%2Fworkflows%2Ftest.yml)

@@ -7,35 +7,43 @@ send emails, html and attachments (files, streams and strings) from node.js to any smtp server

npm install emailjs
npm install emailjs
## FEATURES
- works with SSL and TLS smtp servers
- supports smtp authentication ('PLAIN', 'LOGIN', 'CRAM-MD5', 'XOAUTH2')
- emails are queued and the queue is sent asynchronously
- supports sending html emails and emails with multiple attachments (MIME)
- attachments can be added as strings, streams or file paths
- supports utf-8 headers and body
- works with SSL and TLS smtp servers
- supports smtp authentication ('PLAIN', 'LOGIN', 'CRAM-MD5', 'XOAUTH2')
- emails are queued and the queue is sent asynchronously
- supports sending html emails and emails with multiple attachments (MIME)
- attachments can be added as strings, streams or file paths
- supports utf-8 headers and body
## REQUIRES
- auth access to an SMTP Server
- if your service (ex: gmail) uses two-step authentication, use an application specific password
- auth access to an SMTP Server
- if your service (ex: gmail) uses two-step authentication, use an application specific password
## EXAMPLE USAGE - text only emails
```javascript
var email = require("./path/to/emailjs/email");
var server = email.server.connect({
user: "username",
password:"password",
host: "smtp.your-email.com",
ssl: true
```js
import { SMTPClient } from 'emailjs';
const client = new SMTPClient({
user: 'user',
password: 'password',
host: 'smtp.your-email.com',
ssl: true,
});
// send the message and get a callback with an error or details of the message that was sent
server.send({
text: "i hope this works",
from: "you <username@your-email.com>",
to: "someone <someone@your-email.com>, another <another@your-email.com>",
cc: "else <else@your-email.com>",
subject: "testing emailjs"
}, function(err, message) { console.log(err || message); });
client.send(
{
text: 'i hope this works',
from: 'you <username@your-email.com>',
to: 'someone <someone@your-email.com>, another <another@your-email.com>',
cc: 'else <else@your-email.com>',
subject: 'testing emailjs',
},
(err, message) => {
console.log(err || message);
}
);
```

@@ -45,60 +53,65 @@

```javascript
var email = require("./path/to/emailjs/email");
var server = email.server.connect({
user: "username",
password:"password",
host: "smtp.your-email.com",
ssl: true
```js
import { SMTPClient } from 'emailjs';
const client = new SMTPClient({
user: 'user',
password: 'password',
host: 'smtp.your-email.com',
ssl: true,
});
var message = {
text: "i hope this works",
from: "you <username@your-email.com>",
to: "someone <someone@your-email.com>, another <another@your-email.com>",
cc: "else <else@your-email.com>",
subject: "testing emailjs",
attachment:
[
{data:"<html>i <i>hope</i> this works!</html>", alternative:true},
{path:"path/to/file.zip", type:"application/zip", name:"renamed.zip"}
]
const message = {
text: 'i hope this works',
from: 'you <username@your-email.com>',
to: 'someone <someone@your-email.com>, another <another@your-email.com>',
cc: 'else <else@your-email.com>',
subject: 'testing emailjs',
attachment: [
{ data: '<html>i <i>hope</i> this works!</html>', alternative: true },
{ path: 'path/to/file.zip', type: 'application/zip', name: 'renamed.zip' },
],
};
// send the message and get a callback with an error or details of the message that was sent
server.send(message, function(err, message) { console.log(err || message); });
client.send(message, function (err, message) {
console.log(err || message);
});
// you can continue to send more messages with successive calls to 'server.send',
// you can continue to send more messages with successive calls to 'client.send',
// they will be queued on the same smtp connection
// or you can create a new server connection with 'email.server.connect'
// to asynchronously send individual emails instead of a queue
// or instead of using the built-in client you can create an instance of 'smtp.SMTPConnection'
```
## EXAMPLE USAGE - sending through hotmail/outlook
## EXAMPLE USAGE - sending through outlook
```javascript
var email = require("./path/to/emailjs/email");
var server = email.server.connect({
user: "username",
password:"password",
host: "smtp-mail.outlook.com",
tls: {ciphers: "SSLv3"}
```js
import { SMTPClient, Message } from 'emailjs';
const client = new SMTPClient({
user: 'user',
password: 'password',
host: 'smtp-mail.outlook.com',
tls: {
ciphers: 'SSLv3',
},
});
var message = {
text: "i hope this works",
from: "you <username@outlook.com>",
to: "someone <someone@your-email.com>, another <another@your-email.com>",
cc: "else <else@your-email.com>",
subject: "testing emailjs",
attachment:
[
{data:"<html>i <i>hope</i> this works!</html>", alternative:true},
{path:"path/to/file.zip", type:"application/zip", name:"renamed.zip"}
]
};
const message = new Message({
text: 'i hope this works',
from: 'you <username@outlook.com>',
to: 'someone <someone@your-email.com>, another <another@your-email.com>',
cc: 'else <else@your-email.com>',
subject: 'testing emailjs',
attachment: [
{ data: '<html>i <i>hope</i> this works!</html>', alternative: true },
{ path: 'path/to/file.zip', type: 'application/zip', name: 'renamed.zip' },
],
});
// send the message and get a callback with an error or details of the message that was sent
server.send(message, function(err, message) { console.log(err || message); });
client.send(message, (err, message) => {
console.log(err || message);
});
```

@@ -108,113 +121,152 @@

```javascript
var email = require("./path/to/emailjs/email");
var server = email.server.connect({
user: "username",
password:"password",
host: "smtp-mail.outlook.com",
tls: {ciphers: "SSLv3"}
```js
import { SMTPClient, Message } from 'emailjs';
const client = new SMTPClient({
user: 'user',
password: 'password',
host: 'smtp-mail.outlook.com',
tls: {
ciphers: 'SSLv3',
},
});
var message = {
text: "i hope this works",
from: "you <username@outlook.com>",
to: "someone <someone@your-email.com>, another <another@your-email.com>",
cc: "else <else@your-email.com>",
subject: "testing emailjs",
attachment:
[
{data: "<html>i <i>hope</i> this works! here is an image: <img src='cid:my-image' width='100' height ='50'> </html>"},
{path:"path/to/file.zip", type:"application/zip", name:"renamed.zip"},
{path:"path/to/image.jpg", type:"image/jpg", headers:{"Content-ID":"<my-image>"}}
]
};
const message = new Message({
text: 'i hope this works',
from: 'you <username@outlook.com>',
to: 'someone <someone@your-email.com>, another <another@your-email.com>',
cc: 'else <else@your-email.com>',
subject: 'testing emailjs',
attachment: [
{
data:
'<html>i <i>hope</i> this works! here is an image: <img src="cid:my-image" width="100" height ="50"> </html>',
},
{ path: 'path/to/file.zip', type: 'application/zip', name: 'renamed.zip' },
{
path: 'path/to/image.jpg',
type: 'image/jpg',
headers: { 'Content-ID': '<my-image>' },
},
],
});
// send the message and get a callback with an error or details of the message that was sent
server.send(message, function(err, message) { console.log(err || message); });
client.send(message, (err, message) => {
console.log(err || message);
});
```
# API
# API
## new SMTPClient(options)
## email.server.connect(options)
```js
// options is an object with the following recognized schema:
const options = {
user, // username for logging into smtp
password, // password for logging into smtp
host, // smtp host (defaults to 'localhost')
port, // smtp port (defaults to 25 for unencrypted, 465 for `ssl`, and 587 for `tls`)
ssl, // boolean or object {key, ca, cert} (if true or object, ssl connection will be made)
tls, // boolean or object (if true or object, starttls will be initiated)
timeout, // max number of milliseconds to wait for smtp responses (defaults to 5000)
domain, // domain to greet smtp with (defaults to os.hostname)
authentication, // array of preferred authentication methods ('PLAIN', 'LOGIN', 'CRAM-MD5', 'XOAUTH2')
logger, // override the built-in logger (useful for e.g. Azure Function Apps, where console.log doesn't work)
};
// NOTE: `host` is trimmed before being used to establish a connection;
// however, the original untrimmed value will still be visible in configuration.
```
// options is an object with the following keys
options =
{
user // username for logging into smtp
password // password for logging into smtp
host // smtp host
port // smtp port (if null a standard port number will be used)
ssl // boolean or object {key, ca, cert} (if true or object, ssl connection will be made)
tls // boolean or object (if true or object, starttls will be initiated)
timeout // max number of milliseconds to wait for smtp responses (defaults to 5000)
domain // domain to greet smtp with (defaults to os.hostname)
authentication // array of preferred authentication methods ('PLAIN', 'LOGIN', 'CRAM-MD5', 'XOAUTH2')
}
## email.server.send(message, callback)
// message can be a smtp.Message (as returned by email.message.create)
// or an object identical to the first argument accepted by email.message.create
## SMTPClient#send(message, callback)
// callback will be executed with (err, message)
// either when message is sent or an error has occurred
```js
// message can be a smtp.Message (as returned by email.message.create)
// or an object identical to the first argument accepted by email.message.create
## message
// callback will be executed with (err, message)
// either when message is sent or an error has occurred
```
// headers is an object ('from' and 'to' are required)
// returns a Message object
## new Message(headers)
// you can actually pass more message headers than listed, the below are just the
// most common ones you would want to use
```js
// headers is an object with the following recognized schema:
const headers = {
from, // sender of the format (address or name <address> or "name" <address>)
to, // recipients (same format as above), multiple recipients are separated by a comma
cc, // carbon copied recipients (same format as above)
bcc, // blind carbon copied recipients (same format as above)
text, // text of the email
subject, // string subject of the email
attachment, // one attachment or array of attachments
};
// the `from` field is required.
// at least one `to`, `cc`, or `bcc` header is also required.
// you can also add whatever other headers you want.
```
headers =
{
text // text of the email
from // sender of the format (address or name <address> or "name" <address>)
to // recipients (same format as above), multiple recipients are separated by a comma
cc // carbon copied recipients (same format as above)
bcc // blind carbon copied recipients (same format as above)
subject // string subject of the email
attachment // one attachment or array of attachments
}
## Message#attach(options)
## email.SMTP.authentication
Can be called multiple times, each adding a new attachment.
```js
// options is an object with the following recognized schema:
const options = {
// one of these fields is required
path, // string to where the file is located
data, // string of the data you want to attach
stream, // binary stream that will provide attachment data (make sure it is in the paused state)
// better performance for binary streams is achieved if buffer.length % (76*6) == 0
// current max size of buffer must be no larger than Message.BUFFERSIZE
// optionally these fields are also accepted
type, // string of the file mime type
name, // name to give the file as perceived by the recipient
charset, // charset to encode attatchment in
method, // method to send attachment as (used by calendar invites)
alternative, // if true, will be attached inline as an alternative (also defaults type='text/html')
inline, // if true, will be attached inline
encoded, // set this to true if the data is already base64 encoded, (avoid this if possible)
headers, // object containing header=>value pairs for inclusion in this attachment's header
related, // an array of attachments that you want to be related to the parent attachment
};
```
## new SMTPConnection(options={})
```js
// options is an object with the following recognized schema:
const options = {
user, // username for logging into smtp
password, // password for logging into smtp
host, // smtp host (defaults to 'localhost')
port, // smtp port (defaults to 25 for unencrypted, 465 for `ssl`, and 587 for `tls`)
ssl, // boolean or object {key, ca, cert} (if true or object, ssl connection will be made)
tls, // boolean or object (if true or object, starttls will be initiated)
timeout, // max number of milliseconds to wait for smtp responses (defaults to 5000)
domain, // domain to greet smtp with (defaults to os.hostname)
authentication, // array of preferred authentication methods ('PLAIN', 'LOGIN', 'CRAM-MD5', 'XOAUTH2')
logger, // override the built-in logger (useful for e.g. Azure Function Apps, where console.log doesn't work)
};
// NOTE: `host` is trimmed before being used to establish a connection;
// however, the original untrimmed value will still be visible in configuration.
```
To target a Message Transfer Agent (MTA), omit all options.
## SMTPConnection#authentication
associative array of currently supported SMTP authentication mechanisms
## attachment
// can be called multiple times, each adding a new attachment
// options is an object with the following possible keys:
options =
{
// one of these fields is required
path // string to where the file is located
data // string of the data you want to attach
stream // binary stream that will provide attachment data (make sure it is in the paused state)
// better performance for binary streams is achieved if buffer.length % (76*6) == 0
// current max size of buffer must be no larger than Message.BUFFERSIZE
// optionally these fields are also accepted
type // string of the file mime type
name // name to give the file as perceived by the recipient
charset // charset to encode attatchment in
method // method to send attachment as (used by calendar invites)
alternative // if true, will be attached inline as an alternative (also defaults type='text/html')
inline // if true, will be attached inline
encoded // set this to true if the data is already base64 encoded, (avoid this if possible)
headers // object containing header=>value pairs for inclusion in this attachment's header
related // an array of attachments that you want to be related to the parent attachment
}
## Authors
eleith
zackschuster
## Testing
npm install -d
npm test
npm install -d
npm test

@@ -221,0 +273,0 @@ ## Contributions

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