[英]Not able to send mail using Nodemailer
It's a basic example for Nodemailer. 这是Nodemailer的基本示例。
var http = require('http');
var port = process.env.PORT || 8080;
var async = require('async');
var nodemailer = require('nodemailer');
// create reusable transporter object using SMTP transport
var mailOptions = {
from: '*********', // sender address
to: 'rishiag.iitd@gmail.com', // list of receivers
subject: 'Hello ✔', // Subject line
text: 'Hello world ✔', // plaintext body
html: '<b>Hello world ✔</b>', // html body
attachments: [
{ // utf-8 string as an attachment
filename: 'text1.txt',
content: 'hello world!'
}]
};
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: '*******',
pass: '****'
}
});
// send mail with defined transport object
var server = http.createServer(function(request, response) {
if (request.url === '/favicon.ico') {
response.writeHead(200, {'Content-Type': 'image/x-icon'} );
response.end();
return;
}
response.writeHead(200, {
"Content-Type": "text/plain"
});
transporter.sendMail(mailOptions, function(error, info){
if(error){
console.log("error is " ,error);
}else{
console.log('Message sent: ' + info.response);
}
});
response.end("Hello World\n");
}).listen(port);
console.log("Node server listening on port " + port);
I am getting following error on going to localhost: 我在进入本地主机时遇到以下错误:
[Error: No transport method defined]
I am using Nodemailer version 1.4.23 on Windows 7. What could be the problem? 我正在Windows 7上使用Nodemailer 1.4.23版。可能是什么问题?
Their initial example appears to mention Gmail
for the service when it should instead be gmail
per other examples provided. 他们最初的示例似乎提到该服务的
Gmail
,而应根据提供的其他示例将其改为gmail
。 Seems to be a documentation issue. 似乎是一个文档问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.