**使用xoauth2设置Nodemailer **

时间:2017-10-28 10:07:17

标签: node.js nodemailer

使用xoauth2 设置节点制作程序     [https://medium.com/@pandeysoni/nodemailer-service-in-node-js-using-smtp-and-xoauth2-7c638a39a37e]

    const express= require('express');
    var app=express();
    const nodemailer = require('nodemailer');
    const xoauth2 = require('xoauth2');

    var smtpTransport = nodemailer.createTransport({
            service:"gmail",
            auth:{
                XOAuth2: {
                    user: 'hemendrak1988@gmail.com',
                    clientId: '32932181006-jirrgmtqul1725n08h6ao00ekacn2rem.apps.googleusercontent.com',
                    clientSecret: 'XZeGvYOE0tbJ3Fz671z2u3MG',
                    refreshToken: '1/C_SM_xJE_cxZ_8w_nLa0yXcAOQOJmE9jUKNyTPMJbqM'
                }
            }
    });


    var mailOptions = {
        from: 'Hemendra <hemendrak1988@gmail.com>',
        to: 'hemendrak1989@gmail.com',
        subject: 'Nodemailer test',
        text: 'Hello World!!'
    }

    smtpTransport.sendMail(mailOptions, function (err, res) {
        if(err)
        {
            console.log('Error');
        } 
        else 
        {
            console.log('Email Sent');
        }
    })

    app.listen(3000,function(){
    console.log("Server is running on port 3000");
    })

我正在尝试通过google.api发送邮件。运行我的代码后,我在控制台上收到一条错误消息。有人可以通过google.api发送邮件吗?

0 个答案:

没有答案