I tried setting up nodemailer
Initially I set it up with my gmail account. I have disabled two-factor authentication on it, and enabled IMAP. Here is the function that is supposed to send emails:
import { sendMailType } from '../../types/sendMail.d';
import nodemailer from 'nodemailer';
export const sendMail: sendMailType = async (to, link) => {
const transporter = nodemailer.createTransport({
host: 'smtp.gmail.email',
port: 587,
secure: false,
auth: {
user: process.env.USER, // exampleFrom@gmail.com
pass: process.env.PASS, // password
},
});
let info = await transporter.sendMail({
from: `Mikita <${process.env.SMTP_USER}>`,
to,
subject: 'Follow the link to confirm your email address',
text: '',
html: `
<div>
<h1>Follow the link to confirm your email address</h1>
<a href="${link}" target="_blank">${link}</a>
</div>
`,
});
return { msg: info.messageId };
};
I was getting the following error:
Error: getaddrinfo ENOTFOUND smtp.gmail.email
I tried to run nslookup smtp.gmail.com
and got the error: *** UnKnown unable to find smtp.gmail.com: No response from server
After that I tried setting up a test email so I converted the function to:
import { sendMailType } from '../../types/sendMail.d';
import nodemailer from 'nodemailer';
export const sendMail: sendMailType = async (to, link) => {
let testAccount = await nodemailer.createTestAccount();
const transporter = nodemailer.createTransport({
host: 'smtp.ethereal.email',
port: 587,
secure: false,
auth: {
user: testAccount.user,
pass: testAccount.pass,
},
});
let info = await transporter.sendMail({
from: `Mikita <${process.env.SMTP_USER}>`,
to,
subject: 'Follow the link to confirm your email address',
text: '',
html: `
<div>
<h1>Follow the link to confirm your email address</h1>
<a href="${link}" target="_blank">${link}</a>
</div>
`,
});
return { msg: info.messageId };
};
I am assuming I have some kind of a DNS problem. How could I fix it?
Via Active questions tagged javascript - Stack Overflow https://ift.tt/JTFRdio
Comments
Post a Comment