@sap-cloud-sdk/mail-client
Advanced tools
Comparing version 3.22.2-20241010014057.0 to 3.22.2-20241010084441.0
@@ -330,18 +330,1 @@ import type { Readable } from 'stream'; | ||
} | ||
/** | ||
* @internal | ||
*/ | ||
interface ReadableState { | ||
readableListening: boolean; | ||
} | ||
/** | ||
* Represents a socket object used for On-Premise proxy. | ||
* @internal | ||
*/ | ||
export interface SocksSocket extends net.Socket { | ||
/** | ||
* @internal | ||
*/ | ||
_readableState: ReadableState; | ||
} | ||
export {}; |
@@ -88,9 +88,42 @@ "use strict"; | ||
}; | ||
const socketConnection = await socks_1.SocksClient.createConnection(connectionOptions); | ||
const socksSocket = socketConnection.socket; | ||
// Setting `_readableListening` to true in the next line makes the socket readable. | ||
// Otherwise nodemailer is not able to receive the SMTP greeting message and send emails. | ||
socksSocket._readableState.readableListening = true; | ||
return socksSocket; | ||
const { socket } = await socks_1.SocksClient.createConnection(connectionOptions); | ||
// Workaround for incorrect order of events in nodemailer https://github.com/nodemailer/nodemailer/issues/1684 | ||
await resendGreetingUntilReceived(socket); | ||
return socket; | ||
} | ||
function retrieveGreeting(socket) { | ||
logger.debug('Waiting for SMTP greeting message...'); | ||
return new Promise((resolve, reject) => { | ||
const onData = data => { | ||
logger.debug(`Data received from mail socket: ${data?.toString()}`); | ||
if (data?.toString().startsWith('220')) { | ||
logger.debug('Removing mail socket listeners...'); | ||
socket.removeListener('data', onData); | ||
socket.removeListener('error', onError); | ||
resolve(data); | ||
} | ||
}; | ||
const onError = err => { | ||
reject(new Error(err)); | ||
}; | ||
socket.on('data', onData); | ||
socket.on('error', onError); | ||
}); | ||
} | ||
async function resendGreetingUntilReceived(socket) { | ||
const greeting = await retrieveGreeting(socket); | ||
// resend the greeting message every second until a listener is attached | ||
const intervalId = setInterval(() => { | ||
// note: this is dangerous because there could be another listener that is not the mailer | ||
if (socket.listenerCount('data')) { | ||
socket.emit('data', greeting); | ||
clearInterval(intervalId); | ||
clearTimeout(timeoutId); | ||
} | ||
}, 1000); | ||
const timeoutId = setTimeout(() => { | ||
clearInterval(intervalId); | ||
// default greeting timeout from nodemailer | ||
}, 30 * 1000); | ||
} | ||
function createTransport(mailDestination, mailClientOptions, socket) { | ||
@@ -97,0 +130,0 @@ const baseOptions = { |
{ | ||
"name": "@sap-cloud-sdk/mail-client", | ||
"version": "3.22.2-20241010014057.0", | ||
"version": "3.22.2-20241010084441.0", | ||
"description": "SAP Cloud SDK for JavaScript e-mail client", | ||
@@ -41,4 +41,4 @@ "homepage": "https://sap.github.io/cloud-sdk/docs/js/overview", | ||
"dependencies": { | ||
"@sap-cloud-sdk/connectivity": "^3.22.2-20241010014057.0", | ||
"@sap-cloud-sdk/util": "^3.22.2-20241010014057.0", | ||
"@sap-cloud-sdk/connectivity": "^3.22.2-20241010084441.0", | ||
"@sap-cloud-sdk/util": "^3.22.2-20241010084441.0", | ||
"nodemailer": "6.9.15", | ||
@@ -45,0 +45,0 @@ "socks": "2.8.3" |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41910
698