node.js nodemailer and nodemailer-sendinblue-transport failing to send email

Viewed 4862

I have created an account with sendInBlue and imported nodemailer and nodemailer-sendinblue-transport into my project where I am trying to send a simply confirmation email. The following code is how I have attempted to setup:

const transporter = nodemailer.createTransport(
  sendinblueTransport({
    auth: {
      apiKey: 'key'
    }
  })
);

The following code is a section of my signup method responsible for sending the confirmation email:

return transporter.sendMail({
  to: email,
  from: 'person@gmail.com',
  subject: 'Signup succeeded!',
  html: '<h1>You successfully signed up!</h1>'
});

When I run my program the signup process succeeds but the following error is thrown instead of the email sending:

Error: Key Not Found In Database (failure, 401)

I read that their v2 API might be depreciated but a member of their customer support says they still provide support for nodemailer, what could be the problem? I've also tried sendGrid and Mandrill but the former has a very buggy website that doesn't let me login and the latter requires an active domain to send emails.

Thanks

3 Answers

you can resolve it using this way:

const transporter = nodemailer.createTransport({
    service: 'SendinBlue', // no need to set host or port etc.
    auth: {
        user: 'yourRegisteredEmailOnSendinblue@email.com',
        pass: 'smtp password here'
    }
});

Then you can call it as :

transporter.sendMail({
            to: 'recipientEmail@email.com',
            from: 'senderEmail@email.com',
            subject: 'Signup verification',
            html: '<h1>Please verify your email</h1><a href="www.google.com"> 
                   <button>Verify</button>'
        })
                .then((res) => console.`enter code here`log("Successfully sent"))
                .catch((err) => console.log("Failed ", err))

This worked for me:

const nodemailer = require('nodemailer');
const sibTransport = require('nodemailer-sendinblue-transport');

transport = nodemailer.createTransport(sibTransport({
    apiKey: '<my API v2 product key>',
  }));

Then send as described by @Shashank.

Seems API url for v3 keys is "https://api.sendinblue.com/v3/" Default createTransport uses "https://api.sendinblue.com/v2/"

That`s why it is not worked from the start

Related