SAP / cloud-sdk-js

Use the SAP Cloud SDK for JavaScript / TypeScript to reduce development effort when building applications on SAP Business Technology Platform that communicate with SAP solutions and services such as SAP S/4HANA Cloud, SAP SuccessFactors, and many others.
Apache License 2.0
167 stars 57 forks source link

sendMail trows Error: Greeting never received for Proxy Type OnPremise #5015

Closed gregorwolf closed 1 month ago

gregorwolf commented 1 month ago

Describe the bug

With the commit add @sap-cloud-sdk/mail-client to send mails I've added the Send e-mails functionality to my CAP Multitenant demo app mtxs-bookshop. With the REST Client Test Script test/use-deployed.http I can trigger the sendMail function in the deployed tenant. My SMTP test server is an instance of https://inbucket.org/ running in docker. When I configure a destination with Proxy Type "Internet" in the Subscriber Subaccount all works fine. But as soon as I switch to a destination with Proxy Type "OnPremise" I get the following error message:

OUT [odata|db0f6be2-a8bb-4576-9a67-c7cba89b99b9] - POST /odata/v4/catalog/sendmail
OUT [cat-service|db0f6be2-a8bb-4576-9a67-c7cba89b99b9] - Error: Greeting never received
OUT at SMTPConnection._formatError (/home/vcap/deps/0/node_modules/nodemailer/lib/smtp-connection/index.js:807:19)
OUT at SMTPConnection._onError (/home/vcap/deps/0/node_modules/nodemailer/lib/smtp-connection/index.js:793:20)
OUT at Timeout.<anonymous> (/home/vcap/deps/0/node_modules/nodemailer/lib/smtp-connection/index.js:727:22)
OUT at listOnTimeout (node:internal/timers:573:17)
OUT at process.processTimers (node:internal/timers:514:7) {
OUT code: 'ETIMEDOUT',
OUT command: 'CONN'
OUT }
ERR [cds|db0f6be2-a8bb-4576-9a67-c7cba89b99b9] - Error: Greeting never received
ERR at SMTPConnection._formatError (/home/vcap/deps/0/node_modules/nodemailer/lib/smtp-connection/index.js:807:19)
ERR at SMTPConnection._onError (/home/vcap/deps/0/node_modules/nodemailer/lib/smtp-connection/index.js:793:20)
ERR at Timeout.<anonymous> (/home/vcap/deps/0/node_modules/nodemailer/lib/smtp-connection/index.js:727:22)
ERR at listOnTimeout (node:internal/timers:573:17)
ERR at process.processTimers (node:internal/timers:514:7) {
ERR code: 'ETIMEDOUT',
ERR command: 'CONN',
ERR numericSeverity: 4,
ERR id: '1121184',
ERR level: 'ERROR',
ERR timestamp: 1726745835877
ERR }

A trace in SAP Could Connector is attached here: scc_core.trc.txt

By searching for Greeting never received I found #3636 which was closed. But I think this might be a regression.

To Reproduce Steps to reproduce the behavior:

  1. Deploy my sample project mtxs-bookshop
  2. Maintain the credentials needed for the REST Client script test/use-deployed.http in the test/.env file
  3. Authenticate by running use-deployed.http#L3
  4. Test with the request use-deployed.http#L83

Expected behavior

E-Mails can be sent via SAP Cloud Connector using On Premise SMTP Server.

Screenshots

In the Cloud Connector I can see that a request is received to the virtual host of the SMTP Server:

Virtual Systems Usage

Used Versions:

Code Examples

See above.

Log file

See above.

Impact / Priority

Affected development phase: Production

Impact: Impaired

gregorwolf commented 1 month ago

Hi @jjtang1985 @deekshas8 can you please look into this issue?

deekshas8 commented 1 month ago

Hi @gregorwolf,

We currently don't support Node v20, this might be the potential cause of the error. Can you please try with v18?

gregorwolf commented 1 month ago

According to https://nodejs.org/en/about/previous-releases Node.JS v18 is in Maintenance since End of 2023. v20 is the currently Active but soon v22 will become the Active. So I'm wondering when the Cloud SDK will do the upgrade as also CAP supports >=18.

gregorwolf commented 1 month ago

Hi @deekshas8,

in the branch https://github.com/gregorwolf/mtxs-bookshop/tree/test-node-18 I've downgraded now to Node.JS 18 and I can confirm that this fixed the problem in my sample project. But in our productive product we will not downgrade the Node.JS Version. So when will the Cloud SDK support Node.JS 20 and 22?

gregorwolf commented 1 month ago

Please find here the tunnel traffic trace for Node.JS 18 and 20:

For Node.JS 20 I can see that a connection is made and the SMTP server sends 220 inbucket Inbucket SMTP ready back. But then after 30 seconds without receiving any data it terminates the connection with 221 Idle timeout, bye bye.

gregorwolf commented 1 month ago

At What's New for SAP Business Technology Platform you will find that the Node 18 deprecation is already starting. Continuous Integration & Delivery announced:

The MTA build tool version Java 8 Node 18 is deprecated and will be removed soon.

marikaner commented 1 month ago

Hey @gregorwolf, this is officially planned for Q1 2025, when we also would like to release a version 4 of the SDK. We are currently low on capacity and this issue is not straight forward to fix. However, I understand the urgency and will investigate whether we can fix that ahead of time. I can't promise anything, though.

If you have a solution in mind feel free to point it out or even better contribute it.

marikaner commented 1 month ago

Hey @gregorwolf, I am happy to let you know that we found a fix for this issue. For full transparency, we are quite sure that this solution is merely a workaround for a bug in the underlying library that sends the e-mails.

You can try it out with the canary version right away and expect the fix to be part of the next release.

gregorwolf commented 1 month ago

Hi @marikaner,

that is great news. The version that contains the patch would be 3.22.2-20241010084441.0 then?

marikaner commented 1 month ago

correct

gregorwolf commented 1 month ago

Hi @marikaner,

I've upgraded mtxs-bookshop/blob/main/package.json#L23 to the new package and tested it successful.

Thank you for the efforts.

gregorwolf commented 1 month ago

@marikaner will the 3.22.2 release be published then next week?

jjtang1985 commented 1 month ago

Hi @gregorwolf , The patch version 3.22.2 has been published.