piejanssens / sap-cf-socks

Apache License 2.0
2 stars 1 forks source link

Using the proxy class for nodemailer #2

Open T1mey opened 2 years ago

T1mey commented 2 years ago

Hello @piejanssens,

like you class and wanted to reuse it for nodemailer. (on-premise smtp server) Just struggeling a bit with it.

Do you have any experience with nodemailer and your socks class?

The idea is to set the socks5 proxy handler to your socket.

let proxy = `socks5://${connectivity.proxy.host}:${connectivity.onpremise_socks5_proxy_port}`;

// create reusable transporter object using the default SMTP transport
        const transporter  = nodemailer.createTransport(<SMTPTransport.Options>{
            ...this.transportConfig,
            host: 'somehost.net',
            port: '22',
            secure: false, // true for 465, false for other ports
            secureConnection: false,
            debug: true,
            ignoreTLS: true,
            tls: {
                // do not fail on invalid certs
                rejectUnauthorized: false
            },
            proxy
        });

  let socks = require('socks'); 
  transporter.set('proxy_socks_module', socks);            

  transporter.set('proxy_handler_socks5', (proxy, options, callback) => {
      console.log('Proxy host=% port=%', proxy.hostname, proxy.port);

      let btpSocket = new ConnectivitySocks().getSocket();

      callback(null, {
          connection: btpSocket
      });

  });
piejanssens commented 2 years ago

No experience with nodemailer in combination with socks on BTP's connectivity. Are you familiar with the sap-cf-mailer npm module? It might be easier to implement it that way.

https://blogs.sap.com/2019/11/28/send-an-email-from-a-nodejs-application/

T1mey commented 2 years ago

No experience with nodemailer in combination with socks on BTP's connectivity. Are you familiar with the sap-cf-mailer npm module? It might be easier to implement it that way.

https://blogs.sap.com/2019/11/28/send-an-email-from-a-nodejs-application/

Yes I saw that already. But this ist not supporting onpremise (SMTP) Connections

piejanssens commented 2 years ago

Then you can certainly try with a custom implementation inspired by or using this module, but I have no experience with it. Let us know how it goes !

T1mey commented 2 years ago

Then you can certainly try with a custom implementation inspired by or using this module, but I have no experience with it. Let us know how it goes !

I have now nodemailer running with the socks example from this site

https://blogs.sap.com/2022/02/21/using-the-tcp-protocol-for-node.js-cloud-applications/

When I'm using your class / socket there is something wrong. I'm getting a failure response from our smtp server:

Error: Invalid greeting. response=\u0005€\u0001\u0000\u0005\u0000\u0000\u0001\u0000\u0000\u0000\u0000\u0000\u0000220 server.company.net ESMTP Postfix (SMTPOUT-Relay-3): \u0005€\u0001\u0000\u0005\u0000\u0000\u0001\u0000\u0000\u0000\u0000\u0000\u0000220 server.company.net ESMTP Postfix (SMTPOUT-Relay-3)"," at SMTPConnection._actionGreeting (/home/vcap/app/node_modules/nodemailer/lib/smtp-connection/index.js:1208:27)"," at SMTPConnection._processResponse (/home/vcap/app/node_modules/nodemailer/lib/smtp-connection/index.js:950:20)

As I saw is that the coding is comparable... Do you have any idea what might be the difference?

maheshmagar18 commented 2 years ago

Then you can certainly try with a custom implementation inspired by or using this module, but I have no experience with it. Let us know how it goes !

I have now nodemailer running with the socks example from this site

https://blogs.sap.com/2022/02/21/using-the-tcp-protocol-for-node.js-cloud-applications/

When I'm using your class / socket there is something wrong. I'm getting a failure response from our smtp server:

Error: Invalid greeting. response=\u0005€\u0001\u0000\u0005\u0000\u0000\u0001\u0000\u0000\u0000\u0000\u0000\u0000220 server.company.net ESMTP Postfix (SMTPOUT-Relay-3): \u0005€\u0001\u0000\u0005\u0000\u0000\u0001\u0000\u0000\u0000\u0000\u0000\u0000220 server.company.net ESMTP Postfix (SMTPOUT-Relay-3)"," at SMTPConnection._actionGreeting (/home/vcap/app/node_modules/nodemailer/lib/smtp-connection/index.js:1208:27)"," at SMTPConnection._processResponse (/home/vcap/app/node_modules/nodemailer/lib/smtp-connection/index.js:950:20)

As I saw is that the coding is comparable... Do you have any idea what might be the difference?

Hi T1mey im trying to acheive same can you provide some reference about solution??any repo link or your code sample would be nice....