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 {
|
||||
/**
|
||||
* @typedef {Object} SMTPSocketOptions
|
||||
* @property {string} key
|
||||
* @property {string} ca
|
||||
* @property {string} cert
|
||||
*
|
||||
* @typedef {Object} SMTPOptions
|
||||
* @property {number} [timeout]
|
||||
* @property {string} [user]
|
||||
@ -84,8 +89,8 @@ class SMTP extends EventEmitter {
|
||||
* @property {string} [domain]
|
||||
* @property {string} [host]
|
||||
* @property {number} [port]
|
||||
* @property {boolean} [ssl]
|
||||
* @property {boolean} [tls]
|
||||
* @property {boolean|SMTPSocketOptions} [ssl]
|
||||
* @property {boolean|SMTPSocketOptions} [tls]
|
||||
* @property {string[]} [authentication]
|
||||
*
|
||||
* @constructor
|
||||
@ -157,14 +162,24 @@ class SMTP extends EventEmitter {
|
||||
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}
|
||||
@ -308,7 +323,7 @@ class SMTP extends EventEmitter {
|
||||
this.sock = connect(
|
||||
this.port,
|
||||
this.host,
|
||||
{},
|
||||
typeof this.ssl === 'object' ? this.ssl : {},
|
||||
connected
|
||||
);
|
||||
} else {
|
||||
@ -420,7 +435,9 @@ class SMTP extends EventEmitter {
|
||||
err.message += ' while establishing a starttls session';
|
||||
caller(callback, err);
|
||||
} else {
|
||||
const secureContext = createSecureContext({});
|
||||
const secureContext = createSecureContext(
|
||||
typeof this.tls === 'object' ? this.tls : {}
|
||||
);
|
||||
const secureSocket = new TLSSocket(this.sock, { secureContext });
|
||||
|
||||
secureSocket.on('error', err => {
|
||||
|
Loading…
Reference in New Issue
Block a user