我試圖用nodemailer
模塊發送電子郵件給用戶使用node.js,但它拋出了下面的錯誤。使用Node.js實現nodemailer發送郵件時出錯error
錯誤:
this.transporter.mailer = this;
^
TypeError: Cannot create property 'mailer' on string 'SMTP'
at Mail (/opt/lampp/htdocs/heroku/FGDP/node_modules/nodemailer/lib/mailer/index.js:45:33)
at Object.module.exports.createTransport (/opt/lampp/htdocs/heroku/FGDP/node_modules/nodemailer/lib/nodemailer.js:46:14)
at Object.<anonymous> (/opt/lampp/htdocs/heroku/FGDP/api/api.js:8:32)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
我解釋下面我的代碼。
var nodemailer = require("nodemailer");
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "[email protected]",
pass: "***********"
}
});
在這裏我需要發送郵件給有效的用戶,但得到上述錯誤。
根據[本文檔(https://nodemailer.com/smtp/),第一個參數是一個JavaScript對象,而不是字符串「 SMTP」。 – Myonara