Skip to content
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
697df6f
esm: port code to `--experimental-modules`
zackschuster Sep 18, 2019
cc08daa
rollup: remove require statement
zackschuster Sep 18, 2019
50b9ec1
typescript: naive zero-build-error port
zackschuster Sep 18, 2019
3bb741b
smtp: complete typescript conversion
zackschuster Apr 21, 2020
d57ecc2
test: convert to typescript w/ ava
zackschuster Apr 21, 2020
ae38188
chore: run tests with `--experimental-modules`
zackschuster Apr 23, 2020
8993c49
chore: naively upgrade all deps
zackschuster Apr 23, 2020
16a23e9
chore: update linting
zackschuster Apr 23, 2020
aa7239e
chore: update typescript config
zackschuster Apr 23, 2020
6f1a0e7
chore: lint root files
zackschuster Apr 24, 2020
f3192af
rollup: convert to typescript & output cjs & esm bundles
zackschuster Apr 24, 2020
7062071
chore: set up dual package exports
zackschuster Apr 24, 2020
1727412
smtp: repair differences with pre-conversion code
zackschuster Apr 25, 2020
5d34773
test: don't destructure cjs modules
zackschuster Apr 25, 2020
23fefeb
test: use `.cb` for everything
zackschuster Apr 25, 2020
0c045e1
chore: update gitignore
zackschuster Apr 25, 2020
c1eb2ee
build: include declaration files in output
zackschuster Apr 25, 2020
b97fda8
chore: fix nits
zackschuster Apr 26, 2020
ff606d2
chore: upgrade deps
zackschuster May 1, 2020
288ec6b
test: get (mostly) working
zackschuster May 1, 2020
e3cd104
test: set NODE_TLS_REJECT_UNAUTHORIZED from config
zackschuster May 1, 2020
a1d8b81
chore: disable module mode
zackschuster May 1, 2020
dba555c
build: update distribution config
zackschuster May 1, 2020
03d4f0d
chore: remove old bundle
zackschuster May 1, 2020
9376d37
chore: gitignore new bundle outputs
zackschuster May 1, 2020
b6723b4
chore: move prettier config to separate file
zackschuster May 1, 2020
676c541
chore: move ava config to separate file
zackschuster May 1, 2020
50c3789
test: remove timeouts
zackschuster May 1, 2020
1322ba2
build: don't remove comments
zackschuster May 1, 2020
93f23cd
chore: move type imports from inline statements
zackschuster May 1, 2020
106e5ba
smtp: strongly type addressparser & emailjs-mime-codec
zackschuster May 1, 2020
42a632a
smtp: add Connection to bare SMTP object names
zackschuster May 1, 2020
e0e0f83
chore: update readme
zackschuster May 1, 2020
f7bb694
test: un-skip failing unit
zackschuster May 1, 2020
962e3b0
duty: retire travis
zackschuster May 1, 2020
efe9daa
api: lowercase smtp namespace export
zackschuster May 1, 2020
a537e35
chore: fix nits in manifest
zackschuster May 1, 2020
dc1bd28
smtp: strongly type attachment checks
zackschuster May 1, 2020
3c1681c
smtp: stricten property access modifiers
zackschuster May 1, 2020
ab7ecaf
smtp: specify method access modifiers
zackschuster May 2, 2020
f9d8388
smtp: remove reference to unpublished types
zackschuster May 2, 2020
a945688
chore: remove unused dep
zackschuster May 2, 2020
e6f4cc2
test: use t.is instead of t.deepEqual
zackschuster May 2, 2020
9d80365
lint: enable @typescript-eslint plugin
zackschuster May 24, 2020
4d0b531
chore: upgrade deps
zackschuster May 24, 2020
bb34667
test: fix mailparser timing out smtp
zackschuster May 24, 2020
92e4d7f
build: ready bundle configuration
zackschuster May 24, 2020
ce4683d
test: enable transparent cjs bundle testing
zackschuster May 24, 2020
4bc4d02
chore: add type hint to manifest
zackschuster May 24, 2020
408df22
chore: make export paths relative
zackschuster May 26, 2020
652b021
chore: upgrade deps
zackschuster May 26, 2020
812353a
chore: convert prettier config to json
zackschuster May 26, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 8,
"ecmaFeatures": {
"modules": true
},
"sourceType": "module"
},
"env": {
"es6": true,
"mocha": true,
"node": true
},
"plugins": [
"mocha"
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:prettier/recommended"
"plugin:prettier/recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": [
"error",
{
"ignoreRestArgs": true
}
],
"curly": [
"error",
"all"
Expand All @@ -30,11 +46,6 @@
"ignoreRestSiblings": true
}
],
"valid-jsdoc": "error",
"mocha/handle-done-callback": "error",
"mocha/no-exclusive-tests": "error",
"mocha/no-global-tests": "error",
"mocha/no-mocha-arrows": "error",
"mocha/no-skipped-tests": "error"
"valid-jsdoc": "error"
}
}
27 changes: 15 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ jobs:
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: checkout
uses: actions/checkout@v1
with:
fetch-depth: 1
- name: checkout
uses: actions/checkout@v1
with:
fetch-depth: 1

- name: node
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: node
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: install
run: yarn
- name: install
run: yarn

- name: test
run: yarn test
- name: test
run: yarn test

- name: test-cjs
run: yarn test-cjs
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/.vscode/
/node_modules/
/test/config.js
/npm-debug.log
.vscode
node_modules

*.log
*.swp
*.swo
*~
Expand Down
10 changes: 0 additions & 10 deletions .npmignore

This file was deleted.

8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

193 changes: 110 additions & 83 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# emailjs [![Build Status](https://secure.travis-ci.org/eleith/emailjs.png)](http://travis-ci.org/eleith/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)
# 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)

send emails, html and attachments (files, streams and strings) from node.js to any smtp server

Expand All @@ -21,119 +21,129 @@ send emails, html and attachments (files, streams and strings) from node.js to a
## 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
import { client as c } from 'emailjs';

const client = new c.Client({
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);
});
```

## EXAMPLE USAGE - html emails and attachments

```javascript
var email = require("./path/to/emailjs/email");
var server = email.server.connect({
user: "username",
password:"password",
host: "smtp.your-email.com",
ssl: true
import { client as c } from 'emailjs';

const client = new c.Client({
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"}
import { client as c, message as m } from 'emailjs';

const client = new c.Client({
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 m.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);
});
```

## EXAMPLE USAGE - attaching and embedding an image

```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"}
import { client as c, message as m } from 'emailjs';

const client = new c.Client({
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 m.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

## email.server.connect(options)
## new client.Client(options)

// options is an object with the following keys
options =
Expand All @@ -150,15 +160,15 @@ server.send(message, function(err, message) { console.log(err || message); });
logger // override the built-in logger (useful for e.g. Azure Function Apps, where console.log doesn't work)
}

## email.server.send(message, callback)
## client.Client#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

// callback will be executed with (err, message)
// either when message is sent or an error has occurred

## message
## new message.Message(headers)

// headers is an object ('from' and 'to' are required)
// returns a Message object
Expand All @@ -177,11 +187,7 @@ server.send(message, function(err, message) { console.log(err || message); });
attachment // one attachment or array of attachments
}

## email.SMTP.authentication

associative array of currently supported SMTP authentication mechanisms

## attachment
## message.Message#attach

// can be called multiple times, each adding a new attachment
// options is an object with the following possible keys:
Expand All @@ -207,6 +213,27 @@ associative array of currently supported SMTP authentication mechanisms
related // an array of attachments that you want to be related to the parent attachment
}

## new smtp.SMTPConnection(options)

// 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')
logger // override the built-in logger (useful for e.g. Azure Function Apps, where console.log doesn't work)
}

## smtp.SMTPConnection#authentication

associative array of currently supported SMTP authentication mechanisms

## Authors

eleith
Comment thread
zackschuster marked this conversation as resolved.
Expand Down
8 changes: 8 additions & 0 deletions ava.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
files: ['test/*.ts'],
extensions: ['ts'],
require: ['./email.test.ts'],
environmentVariables: {
NODE_TLS_REJECT_UNAUTHORIZED: '0',
},
};
Loading