节点 google api 电子邮件正文

Node google api body of email

我正在使用节点 googleapi gmail 客户端发送包含以下代码的电子邮件:

var email_lines = ["Content-Type: text/plain; charset=\"UTF-8\"\n",
        "MIME-Version: 1.0\n",
        "Content-Transfer-Encoding: 7bit\n",
        "to: ", "thing@gmail.com", "\n",
        "from: ", "thing2@gmail.io", "\n",
        "subject: ", "the subject", "\n\n",
        "this is the best message"
    ].join('');
    var email = base64.encode(email_lines.trim().replace(/\+/g, '-').replace(/\//g, '_') );

gmail.users.messages.send({
  userId: "thing@gmail.com",
  resource :{
    raw: email
  },
  media:{
    mimeType: "message/rfc822"
  }
},(err,data,body)=>{
  console.log(err);
});

电子邮件已发送,但邮件正文显示在您必须下载的文件中。我怎样才能阻止文件附件并让文本显示在电子邮件中?

您的线路:

var email = base64.encode(email_lines.trim().replace(/\+/g, '-').replace(/\//g, '_') );

实际上应该是:

var email = base64.encode(email_lines.trim()).replace(/\+/g, '-').replace(/\//g, '_');

您需要将邮件编码为 base64,然后进行替换,而不是先进行替换,然后再编码为 base64。