Reputation: 471
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: '[email protected]',
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
Upvotes: 2
Views: 7242
Reputation: 1
For configuring with V3 API what worked for me in 2023:
You have to install nodemailer-sendinblue-transport
package then use this simple configuration.
const nodemailer = require("nodemailer");
const Transport = require("nodemailer-sendinblue-transport");
const transporter = nodemailer.createTransport(
new Transport({ apiKey: "my-api-key" })
);
https://www.npmjs.com/package/nodemailer-sendinblue-transport
Upvotes: 0
Reputation: 2377
If anyone here is not interested in using the module nodemailer-sendinblue-transport module
. Here is the configuration. Tested and it worked.
const transporter = nodemailer.createTransport({
host: 'smtp-relay.sendinblue.com',
port: 587,
auth: {
user: 'YOUR_REGISTERED_EMAIL',
pass: 'YOUR_MASTER_PASSWORD'
}
})
Upvotes: 0
Reputation: 2911
A solution to use Sendinblue with Nest MailerModule
(typescript):
import { Module } from '@nestjs/common'
import { MailerModule } from '@nestjs-modules/mailer'
import { join } from 'path'
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter'
import { ConfigService } from '@nestjs/config'
@Module({
imports: [
MailerModule.forRootAsync({
useFactory: async (config: ConfigService) => ({
transport: {
host: config.get('EMAIL_SMTP_ADDRESS'), // smtp-relay.sendinblue.com
port: Number(config.get('EMAIL_SMTP_PORT')), // 587
secure: false, // for dev purpose
auth: {
user: config.get('EMAIL_USER'), // the Login
pass: config.get('EMAIL_PASSWORD') // any SMTP KEY VALUE (the SMTP KEY NAME is useless...)
}
},
template: {
dir: join(__dirname, 'templates'),
adapter: new HandlebarsAdapter(),
options: {
strict: true
}
}
}),
inject: [ConfigService]
})
]
Upvotes: 0
Reputation: 435
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
Upvotes: 0
Reputation: 552
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.
Upvotes: 1
Reputation: 166
you can resolve it using this way:
const transporter = nodemailer.createTransport({
service: 'SendinBlue', // no need to set host or port etc.
auth: {
user: '[email protected]',
pass: 'smtp password here'
}
});
Then you can call it as :
transporter.sendMail({
to: '[email protected]',
from: '[email protected]',
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))
Upvotes: 15