在邮件发送使用Nodemailer获取错误 [英] Getting error in Mail send Using Nodemailer
本文介绍了在邮件发送使用Nodemailer获取错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建一个项目,并按照 Nodemailer / Gmail - 什么是刷新令牌,如何获得一个?但我是错误。
I create a project and follow all step written in answer of Nodemailer/Gmail - What exactly is a refresh token and how do I get one? but i am error.
我使用以下代码:
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
。
and my second question is how to send attachment. I have only name of file and url
of file.
推荐答案
使用这是因为nodemailer文件中的路径错误。这是nodemailer中的问题使用filepath这是工作
Use this because path wrong in nodemailer doc. this is issue in nodemailer use filepath this is working
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
},
],
这篇关于在邮件发送使用Nodemailer获取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文