mirror of https://github.com/eleith/emailjs.git
smtp: rename Client -> SMTPClient
This commit is contained in:
parent
5b4f95a754
commit
3355154e66
20
Readme.md
20
Readme.md
|
@ -23,9 +23,9 @@ send emails, html and attachments (files, streams and strings) from node.js to a
|
|||
## EXAMPLE USAGE - text only emails
|
||||
|
||||
```js
|
||||
import { Client } from 'emailjs';
|
||||
import { SMTPClient } from 'emailjs';
|
||||
|
||||
const client = new Client({
|
||||
const client = new SMTPClient({
|
||||
user: 'user',
|
||||
password: 'password',
|
||||
host: 'smtp.your-email.com',
|
||||
|
@ -50,9 +50,9 @@ client.send(
|
|||
## EXAMPLE USAGE - html emails and attachments
|
||||
|
||||
```js
|
||||
import { Client } from 'emailjs';
|
||||
import { SMTPClient } from 'emailjs';
|
||||
|
||||
const client = new Client({
|
||||
const client = new SMTPClient({
|
||||
user: 'user',
|
||||
password: 'password',
|
||||
host: 'smtp.your-email.com',
|
||||
|
@ -85,9 +85,9 @@ client.send(message, function (err, message) {
|
|||
## EXAMPLE USAGE - sending through outlook
|
||||
|
||||
```js
|
||||
import { Client, Message } from 'emailjs';
|
||||
import { SMTPClient, Message } from 'emailjs';
|
||||
|
||||
const client = new Client({
|
||||
const client = new SMTPClient({
|
||||
user: 'user',
|
||||
password: 'password',
|
||||
host: 'smtp-mail.outlook.com',
|
||||
|
@ -117,9 +117,9 @@ client.send(message, (err, message) => {
|
|||
## EXAMPLE USAGE - attaching and embedding an image
|
||||
|
||||
```js
|
||||
import { Client, Message } from 'emailjs';
|
||||
import { SMTPClient, Message } from 'emailjs';
|
||||
|
||||
const client = new Client({
|
||||
const client = new SMTPClient({
|
||||
user: 'user',
|
||||
password: 'password',
|
||||
host: 'smtp-mail.outlook.com',
|
||||
|
@ -156,7 +156,7 @@ client.send(message, (err, message) => {
|
|||
|
||||
# API
|
||||
|
||||
## new Client(options)
|
||||
## new SMTPClient(options)
|
||||
|
||||
```js
|
||||
// options is an object with the following recognized schema:
|
||||
|
@ -176,7 +176,7 @@ const options = {
|
|||
// however, the original untrimmed value will still be visible in configuration.
|
||||
```
|
||||
|
||||
## Client#send(message, callback)
|
||||
## SMTPClient#send(message, callback)
|
||||
|
||||
```js
|
||||
// message can be a smtp.Message (as returned by email.message.create)
|
||||
|
|
|
@ -16,7 +16,7 @@ export interface MessageStack {
|
|||
bcc: string[];
|
||||
}
|
||||
|
||||
export class Client {
|
||||
export class SMTPClient {
|
||||
public readonly smtp: SMTPConnection;
|
||||
public readonly queue: MessageStack[] = [];
|
||||
|
||||
|
|
18
test/auth.ts
18
test/auth.ts
|
@ -7,7 +7,7 @@ import {
|
|||
SMTPServerSession,
|
||||
} from 'smtp-server';
|
||||
|
||||
import { AUTH_METHODS, Client, Message } from '../email';
|
||||
import { AUTH_METHODS, SMTPClient, Message } from '../email';
|
||||
|
||||
function onAuth(
|
||||
auth: SMTPServerAuthentication,
|
||||
|
@ -60,7 +60,7 @@ test.cb('no authentication (unencrypted) should succeed', (t) => {
|
|||
},
|
||||
});
|
||||
server.listen(port, () => {
|
||||
new Client({ port }).send(new Message(msg), (err) => {
|
||||
new SMTPClient({ port }).send(new Message(msg), (err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ test.cb('no authentication (encrypted) should succeed', (t) => {
|
|||
},
|
||||
});
|
||||
server.listen(port, () => {
|
||||
new Client({ port, ssl: true }).send(new Message(msg), (err) => {
|
||||
new SMTPClient({ port, ssl: true }).send(new Message(msg), (err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ test.cb('PLAIN authentication (unencrypted) should succeed', (t) => {
|
|||
},
|
||||
});
|
||||
server.listen(port, () => {
|
||||
new Client({
|
||||
new SMTPClient({
|
||||
port,
|
||||
user: 'pooh',
|
||||
password: 'honey',
|
||||
|
@ -161,7 +161,7 @@ test.cb('PLAIN authentication (encrypted) should succeed', (t) => {
|
|||
},
|
||||
});
|
||||
server.listen(port, () => {
|
||||
new Client({
|
||||
new SMTPClient({
|
||||
port,
|
||||
user: 'pooh',
|
||||
password: 'honey',
|
||||
|
@ -199,7 +199,7 @@ test.cb('LOGIN authentication (unencrypted) should succeed', (t) => {
|
|||
},
|
||||
});
|
||||
server.listen(port, () => {
|
||||
new Client({
|
||||
new SMTPClient({
|
||||
port,
|
||||
user: 'pooh',
|
||||
password: 'honey',
|
||||
|
@ -236,7 +236,7 @@ test.cb('LOGIN authentication (encrypted) should succeed', (t) => {
|
|||
},
|
||||
});
|
||||
server.listen(port, () => {
|
||||
new Client({
|
||||
new SMTPClient({
|
||||
port,
|
||||
user: 'pooh',
|
||||
password: 'honey',
|
||||
|
@ -274,7 +274,7 @@ test.cb('XOAUTH2 authentication (unencrypted) should succeed', (t) => {
|
|||
},
|
||||
});
|
||||
server.listen(port, () => {
|
||||
new Client({
|
||||
new SMTPClient({
|
||||
port,
|
||||
user: 'pooh',
|
||||
password: 'honey',
|
||||
|
@ -311,7 +311,7 @@ test.cb('XOAUTH2 authentication (encrypted) should succeed', (t) => {
|
|||
},
|
||||
});
|
||||
server.listen(port, () => {
|
||||
new Client({
|
||||
new SMTPClient({
|
||||
port,
|
||||
user: 'pooh',
|
||||
password: 'honey',
|
||||
|
|
|
@ -2,12 +2,12 @@ import test from 'ava';
|
|||
import { simpleParser } from 'mailparser';
|
||||
import { SMTPServer } from 'smtp-server';
|
||||
|
||||
import { DEFAULT_TIMEOUT, Client, Message } from '../email';
|
||||
import { DEFAULT_TIMEOUT, SMTPClient, Message } from '../email';
|
||||
|
||||
type UnPromisify<T> = T extends Promise<infer U> ? U : T;
|
||||
|
||||
const port = 2526;
|
||||
const client = new Client({
|
||||
const client = new SMTPClient({
|
||||
port,
|
||||
user: 'pooh',
|
||||
password: 'honey',
|
||||
|
@ -48,7 +48,7 @@ test.after.cb((t) => server.close(t.end));
|
|||
|
||||
test.cb('client invokes callback exactly once for invalid connection', (t) => {
|
||||
t.plan(1);
|
||||
const client = new Client({ host: 'bar.baz' });
|
||||
const client = new SMTPClient({ host: 'bar.baz' });
|
||||
const msg = {
|
||||
from: 'foo@bar.baz',
|
||||
to: 'foo@bar.baz',
|
||||
|
@ -69,13 +69,13 @@ test('client has a default connection timeout', (t) => {
|
|||
port: 1234,
|
||||
timeout: undefined as number | null | undefined,
|
||||
};
|
||||
t.is(new Client(connectionOptions).smtp.timeout, DEFAULT_TIMEOUT);
|
||||
t.is(new SMTPClient(connectionOptions).smtp.timeout, DEFAULT_TIMEOUT);
|
||||
|
||||
connectionOptions.timeout = null;
|
||||
t.is(new Client(connectionOptions).smtp.timeout, DEFAULT_TIMEOUT);
|
||||
t.is(new SMTPClient(connectionOptions).smtp.timeout, DEFAULT_TIMEOUT);
|
||||
|
||||
connectionOptions.timeout = undefined;
|
||||
t.is(new Client(connectionOptions).smtp.timeout, DEFAULT_TIMEOUT);
|
||||
t.is(new SMTPClient(connectionOptions).smtp.timeout, DEFAULT_TIMEOUT);
|
||||
});
|
||||
|
||||
test('client deduplicates recipients', (t) => {
|
||||
|
@ -85,7 +85,7 @@ test('client deduplicates recipients', (t) => {
|
|||
cc: 'gannon@gmail.com',
|
||||
bcc: 'gannon@gmail.com',
|
||||
};
|
||||
const stack = new Client({}).createMessageStack(new Message(msg));
|
||||
const stack = new SMTPClient({}).createMessageStack(new Message(msg));
|
||||
t.true(stack.to.length === 1);
|
||||
t.is(stack.to[0].address, 'gannon@gmail.com');
|
||||
});
|
||||
|
@ -159,11 +159,11 @@ test.cb('client allows message with only `bcc` recipient header', (t) => {
|
|||
});
|
||||
|
||||
test('client constructor throws if `password` supplied without `user`', (t) => {
|
||||
t.notThrows(() => new Client({ user: 'anything', password: 'anything' }));
|
||||
t.throws(() => new Client({ password: 'anything' }));
|
||||
t.notThrows(() => new SMTPClient({ user: 'anything', password: 'anything' }));
|
||||
t.throws(() => new SMTPClient({ password: 'anything' }));
|
||||
t.throws(
|
||||
() =>
|
||||
new Client({ username: 'anything', password: 'anything' } as Record<
|
||||
new SMTPClient({ username: 'anything', password: 'anything' } as Record<
|
||||
string,
|
||||
unknown
|
||||
>)
|
||||
|
|
|
@ -5,10 +5,10 @@ import test from 'ava';
|
|||
import { simpleParser } from 'mailparser';
|
||||
import { SMTPServer } from 'smtp-server';
|
||||
|
||||
import { Client, Message, MessageAttachment } from '../email';
|
||||
import { SMTPClient, Message, MessageAttachment } from '../email';
|
||||
|
||||
const port = 2526;
|
||||
const client = new Client({
|
||||
const client = new SMTPClient({
|
||||
port,
|
||||
user: 'pooh',
|
||||
password: 'honey',
|
||||
|
|
Loading…
Reference in New Issue