【问题标题】:Not able to send mail using Nodemailer无法使用 Nodemailer 发送邮件
【发布时间】:2014-09-25 05:17:46
【问题描述】:

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

我在访问 localhost 时遇到以下错误:

[Error: No transport method defined]

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

【问题讨论】:

  • 也许可以尝试service: 'gmail' 和/或尝试在 HTTP 服务器请求之外发送电子邮件。将其归结为基本示例。
  • 谢谢。写gmail 解决了这个问题。他们的文档提到了Gmail。将在 Github 上通知他们。如果您写下答案,我会接受。将来可能会对某人有所帮助。
  • 我也注意到第一个示例有Gmail,而页面下方的另一个示例有gmail。很高兴它有帮助。

标签: javascript node.js nodemailer


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-01
    • 2017-12-06
    • 2021-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多