小编Μελ*_*πας的帖子

Google 禁用不太确定的应用程序选项后,如何使用 Nodemailer 向 Google 发送电子邮件?

我想找到一种方法,nodemailer通过某种谷歌身份验证或任何其他方式从我的应用程序向用户发送电子邮件。在 Google 禁用不太安全的应用程序选项后,下面提到的工作代码已停止工作。

const nodemailer = require('nodemailer')

const sendEmail = async options => {
const transporter = nodemailer.createTransport({
    // host: "smtp.gmail.com",
    // port: "465",
    // secure: true,
    service:'gmail',
    auth: {
        user: "USER_EMAIL",
        pass: "USER_PASSWORD"
    },
    tls:{rejectUnauthorized:false}
})

const message = {
    from: `${process.env.FROM_NAME} <${process.env.FROM_EMAIL}>`,
    to: options.email,
    subject: options.subject,
    text: options.message,
    html: options.message,
    attachments: [
        {
            filename: '.png',
            path: __dirname + '.png',
            cid: '.png'
        }
    ]
}

const info = await transporter.sendMail(message)
console.log('Message sent : %s', info.messageId)
console.log(__dirname)
} …
Run Code Online (Sandbox Code Playgroud)

gmail node.js oauth-2.0 nodemailer

19
推荐指数
1
解决办法
1万
查看次数

标签 统计

gmail ×1

node.js ×1

nodemailer ×1

oauth-2.0 ×1