gpt4 book ai didi

javascript - 无法使用 Nodemailer 发送邮件

转载 作者:搜寻专家 更新时间:2023-11-01 00:43:39 25 4
gpt4 key购买 nike

这是 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);

我在转到本地主机时遇到以下错误:

[Error: No transport method defined]

我在 Windows 7 上使用 Nodemailer 1.4.23 版。可能是什么问题?

最佳答案

他们的初始示例似乎提到了服务的 Gmail,而根据提供的其他示例应该是 gmail。似乎是文档问题。

关于javascript - 无法使用 Nodemailer 发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26031060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com