我创建一个项目,并按照回答Nodemailer/Gmail - What exactly is a refresh token and how do I get one?的所有步骤进行操作,但是我错了。

我使用以下代码:

      var smtpTransport = nodemailer.createTransport("SMTP", {
      service: "Gmail",
      connectionTimeout : "7000",
      greetingTimeout : "7000",

      auth: {
        XOAuth2: {
          user: "",
            clientId: "",
            clientSecret: "",
            refreshToken: ""
        }
      }
    });


    var mailOptions = {
        from: "",
        to:usersEmailId,
        subject: 'subject',
        html: 'string Of Html'
    }

        smtpTransport.sendMail(mailOptions, function(error, response){
                                        if(error){
                                            console.log(error);
                                        }else{
                                            console.log("Message sent: " + response.message);
                                        }

                                        smtpTransport.close();
                                    });

出现以下错误
{ [Error: Connection timeout] code: 'ETIMEDOUT', errno: 'ETIMEDOUT', stage: 'init' }
{ [Error: Connection timeout] code: 'ETIMEDOUT', errno: 'ETIMEDOUT', stage: 'init' }

{ [XOAUTH2Error: invalid_client] name: 'XOAUTH2Error', stage: 'auth' }
{ [XOAUTH2Error: invalid_client] name: 'XOAUTH2Error', stage: 'auth' }

我的第二个问题是如何发送附件。我只有文件名和文件的url

最佳答案

使用此方法是因为nodemailer doc中的路径错误。这是在nodemailer使用文件路径的问题,这是工作

attachments : [
    {   // file on disk as an attachment
        filename: 'name Of File',,
        filePath : 'url of file' // stream this file
    },
],

alternatives : [
    {   // file on disk as an attachment
        filename: 'name Of File',
        filePath : 'url of file' // stream this file
    },
],

关于node.js - 使用Nodemailer在邮件发送中遇到错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35794638/

10-11 23:47