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

Nodemailer does not work #3003

Closed
Akumzy opened this issue May 22, 2023 · 23 comments · Fixed by #3457
Closed

Nodemailer does not work #3003

Akumzy opened this issue May 22, 2023 · 23 comments · Fixed by #3457
Labels
bug Something isn't working node.js Compatibility with Node.js APIs

Comments

@Akumzy
Copy link

Akumzy commented May 22, 2023

What version of Bun is running?

0.6.2

What platform is your computer?

Darwin 22.4.0 arm64 arm

What steps can reproduce the bug?

'use strict';
import nodemailer from 'nodemailer';

// async..await is not allowed in global scope, must use a wrapper
async function main() {
  // Generate test SMTP service account from ethereal.email
  // Only needed if you don't have a real mail account for testing
  const transporter = nodemailer.createTransport({
    host: 'smtp.ethereal.email',
    port: 587,
    secure: false, // true for 465, false for other ports
    auth: {
      user: '...',
      pass: '...',
    },
  });

  // send mail with defined transport object
  let info = await transporter.sendMail({
    from: '"Fred Foo 👻" <foo@example.com>', // sender address
    to: 'example@gmail.com', // list of receivers
    subject: 'Hello ✔', // Subject line
    text: 'Hello world?', // plain text body
    html: '<b>Hello world?</b>', // html body
  });

  console.log('Message sent: %s', info.messageId);
  // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>

  // Preview only available when sending through an Ethereal account
  console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
  // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
}

main().catch(console.error);

What is the expected behavior?

To send email successfully

What do you see instead?

Depending on the SMTP credentials I'm getting different errors

1371 |             return;
1372 |         }
1373 | 
1374 |         this._upgradeConnection((err, secured) => {
1375 |             if (err) {
1376 |                 this._onError(new Error('Error initiating TLS - ' + (err.message || err)), 'ETLS', false, 'STARTTLS');
                                 ^
error: Error initiating TLS - Expected "port" to be a number between 0 and 65535
 code: "ETLS"

      at /Users/[redacted]/node_modules/nodemailer/lib/smtp-connection/index.js:1376:30
      at _actionSTARTTLS (/Users/[redacted]/node_modules/nodemailer/lib/smtp-connection/index.js:1374:8)

and also

error: DNS lookup failed: Given hostname is not numeric
 code: "EDNS"

Additional information

No response

@Akumzy Akumzy added the bug Something isn't working label May 22, 2023
@cirospaciari
Copy link
Collaborator

cirospaciari commented May 23, 2023

Missing socket option on tls.connect https://nodejs.org/api/tls.html#tlsconnectoptions-callback

@Akumzy
Copy link
Author

Akumzy commented May 23, 2023

@cirospaciari oh!
Hopefully that'll be added soon

@Electroid Electroid added the node.js Compatibility with Node.js APIs label May 23, 2023
@binary-koan
Copy link

Same as #2981 I think

This is breaking the postgres package for me as well - localhost works but using a remote domain (e.g. with neon.tech) fails with the same error. Looking at the postgres package code, it does seem to be using the socket parameter to connect

@bitdom8
Copy link

bitdom8 commented Jun 28, 2023

any progress? @Akumzy

@Akumzy
Copy link
Author

Akumzy commented Jun 28, 2023

@bitdom8 I really don't know as I've checked again to gotten any feedback from Oven team

@bitdom8
Copy link

bitdom8 commented Jul 3, 2023

nope

@Jarred-Sumner
Copy link
Collaborator

Please give it another try in the canary build in about 40 minutes (once it finishes compiling)

bun upgrade --canary

@bitdom8
Copy link

bitdom8 commented Jul 3, 2023

Sounds like GDA go do action @Jarred-Sumner thanks

@bitdom8
Copy link

bitdom8 commented Jul 7, 2023

It states it's fixed but it's not https://bun.sh/blog/bun-v0.6.13#nodemailer-works. Get

state.length while ret = null 0 Segmentation fault

in running, sometimes get this:

state.length while ret = null 0 290 | }).catch((error) => { 291 | this.emit("error", error); 292 | }); 293 | else 294 | 295 | bunConnect({ ^ error: Failed to connect code: "ECONNECTION"

tried with host: 'smtp.gmail.com', the config and variables works with nodejs fine

@Jarred-Sumner Jarred-Sumner reopened this Jul 7, 2023
@bitdom8
Copy link

bitdom8 commented Jul 7, 2023

ANy success @Jarred-Sumner , can't wait to use bun.sh

@bitdom8
Copy link

bitdom8 commented Jul 9, 2023

@Jarred-Sumner

@bitdom8
Copy link

bitdom8 commented Jul 15, 2023

İt works now. Thank you @Jarred-Sumner

@Jarred-Sumner
Copy link
Collaborator

Jarred-Sumner commented Jul 15, 2023 via email

@bitdom8
Copy link

bitdom8 commented Jul 18, 2023

Thanks. It works when having it runed on cmd linux ssh but when started on .service file:

Jul 18 13:09:02 xxyy xxx.service[751]: error: Error initiating TLS - Expected "port" to be a number between 0 and 65535

what's wrong here? @cirospaciari

@cirospaciari
Copy link
Collaborator

Thanks. It works when having it runed on cmd linux ssh but when started on .service file:

Jul 18 13:09:02 xxyy xxx.service[751]: error: Error initiating TLS - Expected "port" to be a number between 0 and 65535

what's wrong here? @cirospaciari

Looks like it is running an older version, can you confirm the version that is being executed?

@bitdom8
Copy link

bitdom8 commented Jul 18, 2023

Thanks for speedy reply. @cirospaciari It's new

xx@yy:/usr/local/lsws/nodes/xx$ bun -v
0.6.14

this results an error:
sudo /root/.bun/bin/bun --hot serverwh.ts

when I go to folder and run
bun serverwh.ts
all is well. No error as such below:

Jul 18 13:09:02 xxyy xxx.service[751]: error: Error initiating TLS - Expected "port" to be a number between 0 and 65535

@cirospaciari
Copy link
Collaborator

Thanks for speedy reply. @cirospaciari It's new

xx@yy:/usr/local/lsws/nodes/xx$ bun -v
0.6.14

this results an error:
sudo /root/.bun/bin/bun --hot serverwh.ts

when I go to folder and run
bun serverwh.ts
all is well. No error as such below:

Jul 18 13:09:02 xxyy xxx.service[751]: error: Error initiating TLS - Expected "port" to be a number between 0 and 65535

Interesting, can you try sudo /root/.bun/bin/bun upgrade --canary to see if it works?

@bitdom8
Copy link

bitdom8 commented Jul 18, 2023

I understood now. We didn't update with sudo command as sudo curl -fsSL https://bun.sh/install | bash

Thus it was mistaking the old version as a command file. Now it works. However you were right about last version @cirospaciari . Thanks

@cirospaciari
Copy link
Collaborator

I understood now. We didn't update with sudo command as sudo curl -fsSL https://bun.sh/install | bash

Thus it was mistaking the old version as a command file. Now it works

Happy that's worked for you

@bitdom8
Copy link

bitdom8 commented Aug 24, 2023

After update to 0.8, nodemailer not works

if (this.remotePort = port, socket.data = this, socket.timeout(this.timeout), socket.ref(), this[bunSocketInternal] = socket, this.connecting = !1, !this.#upgraded)
218 |       this.emit("connect", this);
219 |     Socket2.#Drain(socket);
220 |   }
221 | 
222 |   connect(port, host, connectListener) {
                     ^
error: Failed to connect
 code: "ECONNECTION"

      at connect (node:net:222:18)
      at /mnt/c/Users/Administrator/Documents/Bun/q/node_modules/nodemailer/lib/smtp-connection/index.js:354:35
      at /mnt/c/Users/Administrator/Documents/Bun/q/node_modules/nodemailer/lib/shared/index.js:152:19
      at /mnt/c/Users/Administrator/Documents/Bun/q/node_modules/nodemailer/lib/shared/index.js:66:15

@cirospaciari @colinhacks Thanks for awesomeness on this amazing lib

@bitdom8
Copy link

bitdom8 commented Aug 24, 2023

Ok, it doesn't work on first try, but in second try, it works.

That's why it doesn't work on linux .service scripts

@bitdom8
Copy link

bitdom8 commented Aug 24, 2023

It doesn't ork also when script is runned from another subfolder as cd subfolder;bun indexapihere.ts

@bitdom8
Copy link

bitdom8 commented Aug 24, 2023

Here is the .service log

Aug 24 19:15:10 nodemailerservice.service[2387]:  syscall: "open"
Aug 24 19:15:10 nodemailerservice.service[2387]:    errno: -6
Aug 24 19:15:10 nodemailerservice.service[2387]:       at new WriteStream2 (node:fs:428:26)
Aug 24 19:15:10 nodemailerservice.service[2387]:       at WriteStream3 (node:fs:419:46)
Aug 24 19:15:10 nodemailerservice.service[2387]:       at new  (node:tty:22:50)
Aug 24 19:15:10 nodemailerservice.service[2387]:       at node:tty:22:50
Aug 24 19:15:10 nodemailerservice.service[2387]:       at getStdioWriteStream (:1:20)
Aug 24 19:15:10 nodemailerservice.service[2387]:       at node:stream:2027:82
Aug 24 19:15:10 nodemailerservice.service[2387]:       at /usr/local/lsws/nodes/bun/node_modules/nodemailer/lib/fetch/index.js:238:12
Aug 24 19:15:10  nodemailerservice.service[2387]:       at node:http:853:28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working node.js Compatibility with Node.js APIs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants