Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the proxy class for nodemailer #2

Open
T1mey opened this issue Sep 20, 2022 · 5 comments
Open

Using the proxy class for nodemailer #2

T1mey opened this issue Sep 20, 2022 · 5 comments

Comments

@T1mey
Copy link

T1mey commented Sep 20, 2022

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
Copy link
Owner

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
Copy link
Author

T1mey commented Sep 20, 2022

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
Copy link
Owner

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
Copy link
Author

T1mey commented Sep 22, 2022

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
Copy link

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....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants