nodemailer / wildduck

Opinionated email server
https://wildduck.email/
European Union Public License 1.2
1.92k stars 268 forks source link

Can't send email to outside domain user from nodemailer. #743

Closed tsalsa919 closed 1 month ago

tsalsa919 commented 1 month ago

I have setup wildduck and I can send email just fine from wildduck-webmail. However, when I try to send an email using nodemailer. Just using the code below.:

const nodemailer = require("nodemailer");

const transporter = nodemailer.createTransport({
        host: "smtp.example.com",
        port: 25,
        secure: false, 
        auth: {
        user: "****@example.com",
        pass: "*******",
        },
});

async function main() { 
  // send mail with defined transport object 
    const info = await transporter.sendMail({ 
                from: '"Dance 👻" <***@******>', // sender address 
                to: "****@gmail.com", // list of receivers 
                subject: "Hello Test from Wildduck Server✔", // Subject line 
                text: "Hello, this is just an auto email from Wildduck server.", // plain text body 
                html: "<b>Hello world new server test?</b>", // html body 
        }); 

    } 

main()

Then I get the following error. The gmail user does exist. And if I replace the to email address to a email on the server (in this case contact@example.com), then it works. I can the email sent in contact@example.com

Any ideas? It it related to some LMTP/SMTP settings in the config?

Following is the error returned by nodemailer.

Error: Can't send mail - all recipients were rejected: 550 5.1.1 No such user    at SMTPConnection._formatError (/home/super/mailer/node_modules/nodemailer/lib/smtp-connection/index.js:807:19)    at SMTPConnection._actionRCPT (/home/super/mailer/node_modules/nodemailer/lib/smtp-connection/index.js:1676:28)    at SMTPConnection.<anonymous> (/home/super/mailer/node_modules/nodemailer/lib/smtp-connection/index.js:1629:30)
    at SMTPConnection._processResponse (/home/super/mailer/node_modules/nodemailer/lib/smtp-connection/index.js:991:20)    at SMTPConnection._onData (/home/super/mailer/node_modules/nodemailer/lib/smtp-connection/index.js:772:14)
    at SMTPConnection._onSocketData (/home/super/mailer/node_modules/nodemailer/lib/smtp-connection/index.js:195:44)
    at TLSSocket.emit (node:events:519:28)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)    at Readable.push (node:internal/streams/readable:390:5) {  code: 'EENVELOPE',
  response: '550 5.1.1 No such user',  responseCode: 550,
  command: 'RCPT TO',
  rejected: [ 'xxxx@gmail.com' ],
  rejectedErrors: [
    Error: Recipient command failed: 550 5.1.1 No such user        at SMTPConnection._formatError (/home/super/mailer/node_modules/nodemailer/lib/smtp-connection/index.js:807:19)        at SMTPConnection._actionRCPT (/home/super/mailer/node_modules/nodemailer/lib/smtp-connection/index.js:1662:24)
        at SMTPConnection.<anonymous> (/home/super/mailer/node_modules/nodemailer/lib/smtp-connection/index.js:1629:30)        at SMTPConnection._processResponse (/home/super/mailer/node_modules/nodemailer/lib/smtp-connection/index.js:991:20)        at SMTPConnection._onData (/home/super/mailer/node_modules/nodemailer/lib/smtp-connection/index.js:772:14)        at SMTPConnection._onSocketData (/home/super/mailer/node_modules/nodemailer/lib/smtp-connection/index.js:195:44)
        at TLSSocket.emit (node:events:519:28)        at addChunk (node:internal/streams/readable:559:12)
        at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
        at Readable.push (node:internal/streams/readable:390:5) {
      code: 'EENVELOPE',
      response: '550 5.1.1 No such user',
      responseCode: 550,
      command: 'RCPT TO',
      recipient: 'xxxx@gmail.com'
    }
  ]
}
louis-lau commented 1 month ago

Port 25 is your MX, your receiving server. This mean you're telling your own MX you have a message for user@gmail.com, to which is of course says it doesn't know that user. Use the submission port 587 instead, that will queue your message in zone-mta.

If you're planning to be run a production mail server I'd recommend learning more about how email systems work before doing so. Happy experimenting!

tsalsa919 commented 1 month ago

Thanks for the tip. I have try it with port 587.

Then I get an SSL error. And I have set up tls.toml to point the proper let's encrypt .pem files. Is it some config in zone-mta?

node:internal/process/promises:391    triggerUncaughtException(err, true /* fromPromise */);
    ^
[Error: 80BC814C517F0000:error:0A000410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:../deps/openssl/openssl/ssl/record/rec_layer_s3.c:1590:SSL alert number 40
] {
  library: 'SSL routines',
  reason: 'sslv3 alert handshake failure',
  code: 'ESOCKET',
  command: 'CONN'
}

Node.js v20.17.0
tsalsa919 commented 1 month ago

Just want to update. Still have NOT being able to figure out how to have zone-mta with the wildduck plugin setup to server starttls.

I have changed the starttls=true and set the key and certs paths correct in

/etc/zone-mta/interfaces/feeder.toml

Still nothing. I have also set the files in /etc/wildduck/tls.toml

For now I just turned starttls=false and connect only using 127.0.0.1 from the localserver and that is working. But it would be good to setup wildduck to be able send SMTP using starttls and use the username/password auth of the wildduck accounts? Or what is the recommended way to setup this for wildduck? Or should we just sent email using API. I notice the role.md file is missing, would be cool if we can just make API call with accessToken for each account only authorized for that account? Is this working or it is in the roadmap?

andris9 commented 1 month ago

Are you sure you are not using STARTTLS if the mail goes through? Nodemailer upgrades the connection to TLS by default.

tsalsa919 commented 1 month ago

Where is the configuration for Wildduck to listen for the network interface that is NOT just 127.0.0.1 ? Is it in Haraka or Zone-mta that is responsible for the port 587 and listening IP?

tsalsa919 commented 1 month ago

Ok so I have figured it out:

/etc/zone-mta/interfaces/feeder.toml

is what is controlling the host and port to listen on.