Невозможно отправлять почту с помощью 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: '[email protected]', // 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]

Я использую Nodemailer версии 1.4.23 в Windows 7. В чем может быть проблема?


person rishiag    schedule 25.09.2014    source источник
comment
Возможно, попробуйте service: 'gmail' и / или попробуйте отправить электронное письмо вне запроса HTTP-сервера. Сведите все к основному примеру.   -  person Kevin Reilly    schedule 25.09.2014
comment
Спасибо. Написание gmail решило проблему. В их документации упоминается Gmail. Сообщу их на Github. Приму, если напишете ответ. Это может кому-то помочь в будущем.   -  person rishiag    schedule 25.09.2014
comment
Я тоже заметил, что в первом примере было Gmail, а в другом примере на странице было gmail. Рад, что помог.   -  person Kevin Reilly    schedule 25.09.2014


Ответы (1)


В их первоначальном примере, похоже, упоминается Gmail для службы, тогда как вместо этого должно быть gmail в других приведенных примерах. Кажется, проблема в документации.

person Kevin Reilly    schedule 25.09.2014