mirror of
https://github.com/eleith/emailjs.git
synced 2024-07-05 20:10:37 +00:00
re-add support for ssl/tls objects
This commit is contained in:
parent
2555912d21
commit
845e2bd489
33
smtp/smtp.js
33
smtp/smtp.js
@ -77,6 +77,11 @@ const SMTPState = {
|
|||||||
|
|
||||||
class SMTP extends EventEmitter {
|
class SMTP extends EventEmitter {
|
||||||
/**
|
/**
|
||||||
|
* @typedef {Object} SMTPSocketOptions
|
||||||
|
* @property {string} key
|
||||||
|
* @property {string} ca
|
||||||
|
* @property {string} cert
|
||||||
|
*
|
||||||
* @typedef {Object} SMTPOptions
|
* @typedef {Object} SMTPOptions
|
||||||
* @property {number} [timeout]
|
* @property {number} [timeout]
|
||||||
* @property {string} [user]
|
* @property {string} [user]
|
||||||
@ -84,8 +89,8 @@ class SMTP extends EventEmitter {
|
|||||||
* @property {string} [domain]
|
* @property {string} [domain]
|
||||||
* @property {string} [host]
|
* @property {string} [host]
|
||||||
* @property {number} [port]
|
* @property {number} [port]
|
||||||
* @property {boolean} [ssl]
|
* @property {boolean|SMTPSocketOptions} [ssl]
|
||||||
* @property {boolean} [tls]
|
* @property {boolean|SMTPSocketOptions} [tls]
|
||||||
* @property {string[]} [authentication]
|
* @property {string[]} [authentication]
|
||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
@ -157,14 +162,24 @@ class SMTP extends EventEmitter {
|
|||||||
this.host = typeof host === 'string' ? host : 'localhost';
|
this.host = typeof host === 'string' ? host : 'localhost';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {boolean}
|
* @type {boolean|SMTPSocketOptions}
|
||||||
*/
|
*/
|
||||||
this.ssl = typeof ssl === 'boolean' ? ssl : false;
|
this.ssl =
|
||||||
|
ssl != null &&
|
||||||
|
(typeof ssl === 'boolean' ||
|
||||||
|
(typeof ssl === 'object' && Array.isArray(ssl) === false))
|
||||||
|
? ssl
|
||||||
|
: false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {boolean}
|
* @type {boolean|SMTPSocketOptions}
|
||||||
*/
|
*/
|
||||||
this.tls = typeof tls === 'boolean' ? tls : false;
|
this.tls =
|
||||||
|
tls != null &&
|
||||||
|
(typeof tls === 'boolean' ||
|
||||||
|
(typeof tls === 'object' && Array.isArray(tls) === false))
|
||||||
|
? tls
|
||||||
|
: false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {number}
|
* @type {number}
|
||||||
@ -308,7 +323,7 @@ class SMTP extends EventEmitter {
|
|||||||
this.sock = connect(
|
this.sock = connect(
|
||||||
this.port,
|
this.port,
|
||||||
this.host,
|
this.host,
|
||||||
{},
|
typeof this.ssl === 'object' ? this.ssl : {},
|
||||||
connected
|
connected
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -420,7 +435,9 @@ class SMTP extends EventEmitter {
|
|||||||
err.message += ' while establishing a starttls session';
|
err.message += ' while establishing a starttls session';
|
||||||
caller(callback, err);
|
caller(callback, err);
|
||||||
} else {
|
} else {
|
||||||
const secureContext = createSecureContext({});
|
const secureContext = createSecureContext(
|
||||||
|
typeof this.tls === 'object' ? this.tls : {}
|
||||||
|
);
|
||||||
const secureSocket = new TLSSocket(this.sock, { secureContext });
|
const secureSocket = new TLSSocket(this.sock, { secureContext });
|
||||||
|
|
||||||
secureSocket.on('error', err => {
|
secureSocket.on('error', err => {
|
||||||
|
Loading…
Reference in New Issue
Block a user