5

I am using the latest version of nodemailer version 4.1.0. I tried using the sample code available here https://nodemailer.com/smtp/

Here is my code

 let transporter = nodemailer.createTransport({
        host: 'smtp.zoho.com',
        port:587,
        secure: false,           
        auth: {
            user: this.user,
            pass: this.password
        }
    });

     var mailOptions: nodemailer.SendMailOptions = {
        from: ****@***.com,
        to: test@abc.com,
        subject: 'Hello ✔',
        text: 'Hello world ✔', 
        html: '<b>Hello world ✔</b>'
    };

   transporter
            .sendMail(mailOptions)
            .then(
                (info) => {
                  //  console.log(info);
                    resolve({status: info.messageId})
                }
            )
            .catch(err => {
             //   console.log(err);
                reject({status: err.toString()})
            })

I get the following error. I have set the secure flag as false, and have also used ignodeTLS. The previous version of nodemailer 0.7.1 did not have any issues. Am I missing out on any specific configuration?

   { Error: Invalid login: 530 Must issue a STARTTLS command first.
at SMTPConnection._formatError 
(C:\Project\NotificationService\node_modules\nodemailer\lib\smtp-connection\index.js:577:19)
at SMTPConnection._actionAUTHComplete (C:\Project\NotificationService\node_modules\nodemailer\lib\smtp-connection\index.js:1306:34)
at SMTPConnection._responseActions.push.str (C:\Project\NotificationService\node_modules\nodemailer\lib\smtp-connection\index.js:349:26)
at SMTPConnection._processResponse (C:\Project\NotificationService\node_modules\nodemailer\lib\smtp-connection\index.js:733:20)
at SMTPConnection._onData (C:\Project\NotificationService\node_modules\nodemailer\lib\smtp-connection\index.js:529:14)
at Socket._socket.on.chunk (C:\Project\NotificationService\node_modules\nodemailer\lib\smtp-connection\index.js:481:47)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:548:20)
  code: 'EAUTH',
  response: '530 Must issue a STARTTLS command first.',
  responseCode: 530,
  command: 'AUTH PLAIN' }
Rahul Ganguly
  • 1,908
  • 5
  • 24
  • 36

3 Answers3

6

you can also use this without these tls parameter default value is false. you got the error because of you don't pass service:'zoho' in nodemailer

let transporter = nodemailer.createTransport({
        service:'Zoho',
        host: this.service,
        port:587,
        secure: false,
        auth: {
            user: this.user,
            pass: this.password
        }
    });
Ricky sharma
  • 701
  • 9
  • 21
3

After going through the typings( "@types/nodemailer") file I added the following flags

1) service :'Zoho'

2) requireTLS :false

it is working now :)

let transporter = nodemailer.createTransport({
        service:'Zoho',
        host: this.service,
        port:587,
        secure: false,
        ignoreTLS:true,
        requireTLS:false,
        auth: {
            user: this.user,
            pass: this.password
        }
    });
Rahul Ganguly
  • 1,908
  • 5
  • 24
  • 36
  • Thanks for your answer. Let's also note that the service string can be anything. If your smtp server is offered by an external provider then the service string is important. you can set it to an empty string but it must be there. – shellking4 Jan 16 '23 at 14:08
1

In the year 2022, I got this on the official documentation https://nodemailer.com/smtp/well-known/

let transporter = nodemailer.createTransport({
     service: 'SendPulse', // no need to set host or port etc.
     auth: {
         user: 'account.email@example.com',
         pass: 'smtp-password'
     }
});

transporter.sendMail(...)

So, for Zoho just simply:

let transporter = nodemailer.createTransport({
     service: 'Zoho', // no need to set host or port etc.
     auth: {
         user: 'account.email@example.com',
         pass: 'smtp-password'
     }
});

transporter.sendMail(...)

Just test it and works. I believe it doesn't need to put any setting if we use "Well-known services"

Hope this helps someone drop by in this thread :).

Bayu
  • 2,340
  • 1
  • 26
  • 31