I made a mail service and wanted to use smtp for mailing, but when I try to log in, the login or password is not accepted, although they are 100 percent entered correctly. What should I do?
import nodemailer from "nodemailer";
import { config } from "dotenv";
config({ path: "./other/.env" });
const SMTP_HOST = process.env.SMTP_HOST || "smtp.gmail.com";
const SMTP_PORT = process.env.SMTP_PORT || 587;
const SMTP_USER = process.env.SMTP_USER || "smpt user is not working";
const SMTP_PASSWORD = process.env.SMTP_PASSWORD || "smtp password is not working";
const SITE_URL = process.env.SITE_URL || "site url is not working";
class MailService {
transporter;
constructor() {
this.transporter = nodemailer.createTransport({
host: SMTP_HOST,
port: SMTP_PORT,
secure: false,
auth: {
user: SMTP_USER,
pass: SMTP_PASSWORD
}
} as nodemailer.TransportOptions);
}
async sendActivationMail(to: string, link: string) {
await this.transporter.sendMail({
from: SMTP_USER,
to,
subject: "Account's activation on " + SITE_URL,
text: '',
html:
`
<div>
<h1>For actovation click on this link</h1>
<a href="${link}">${link}</a>
</div>
`
})
}
}
export default new MailService();
Error: Invalid login: 535-5.7.8 Username and Password not accepted. For more information, go to535 5.7.8 https://support.google.com/mail/?p=BadCredentials x28-20020a056512131c00b0051979e3a586sm1546821lfu.266 - gsmtpat SMTPConnection._formatErrorat SMTPConnection._actionAUTHCompleteat SMTPConnection.<anonymous>at SMTPConnection._processResponseat SMTPConnection._onDataat SMTPConnection._onSocketDataat TLSSocket.emit (node:events:513:28)at addChunk (node:internal/streams/readable:324:12)at readableAddChunk (node:internal/streams/readable:297:9)at Readable.push (node:internal/streams/readable:234:10) {code: 'EAUTH',response: '535-5.7.8 Username and Password not accepted. For more information, go ton' +'535 5.7.8 https://support.google.com/mail/?p=BadCredentials x28-20020a056512131c00b0051979e3a586sm1546821lfu.266 - gsmtp',responseCode: 535,command: 'AUTH PLAIN
I tried all ai chats, not helped.