I am using nodemailer in my current project to send verification links to my users and it didnt work.
I am using nodemailer in my current project to send verification links to my users. When the project is in development mode the mail is sent to the user successfully but when I deployed my web application on cyclic.sh, the mail is not sent.
const nodemailer = require('nodemailer');
const jwt = require("jsonwebtoken");
const path = require("path");
if(process.env.NODE_ENV !== "production") {
require('dotenv').config({ path: path.join(__dirname, "..", ".env") });
}
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.MAIL_ID,
pass: process.env.MAIL_PASSWORD
}
});
module.exports = {
sendVerificationLink: async (id, email, name) => {
const token = jwt.sign({
data: { userid: id, name: name, email: email },
exp: Math.floor(Date.now() / 1000) + (60 * 60)
}, process.env.ACCESS_TOKEN_SECRET);
const mailOptions = {
from: process.env.MAIL_ID,
to: `${email}`,
subject: "Verify your email",
html: `
<p>Hi ${name}, please click on the following link to verify your email</p>
<a href = "http://${process.env.DOMAIN}/auth/verify/${token}">Verify your email</a>
`
};
await transporter.sendMail(mailOptions);
return;
}
}
Even if it isn't on the same subdomain, other people are able to host a site under *.cyclic.sh
. So because people have likely abused that domain in the past, Google has marked the domain as suspicious and will mark the emails as spam, as the error at the top indicates.
Your best bet would be to make your own domain since that won't have a history of abuse, so it should not be flagged.