23

SMTP トランスポートなしで nodemailer 経由で電子メールを送信しようとしています。だから私はそれをやった:

var mail = require("nodemailer").mail;

mail({
    from: "Fred Foo ✔ <foo@blurdybloop.com>", // sender address
    to: "******@gmail.com", // list of receivers
    subject: "Hello ✔", // Subject line
    text: "Hello world ✔", // plaintext body
    html: "<b>Hello world ✔&lt;/b>" // html body
});

しかし、実行すると次のようになります。

> node sendmail.js
Queued message #1 from foo@blurdybloop.com, to vinz243@gmail.com
Retrieved message #1 from the queue, reolving gmail.com
gmail.com resolved to gmail-smtp-in.l.google.com for #1
Connecting to gmail-smtp-in.l.google.com:25 for message #1
Failed processing message #1
Message #1 requeued for 15 minutes
Closing connection to the server

Error: read ECONNRESET
    at errnoException (net.js:901:11)
    at TCP.onread (net.js:556:19)

私はWindows 7 32を使用しています。

編集 これは、Linuxで機能したため、Windows関連のバグのようです

編集#2

git シェルで入力telnet smtp.gmail 587すると、ここでブロックされます。

220 mx.google.com ESMTP f7...y.24 -gsmtp
4

7 に答える 7

16

出力例から、間違ったポート 25 に接続しているように見えます。開いている gmail smtp ポートは、SSL の場合は 465、その他の TLS は 587 です。

Nodemailer は、電子メール ドメインに基づいて正しい構成を検出します。この例では、トランスポーター オブジェクトを設定していないため、構成されているデフォルトのポート 25 を使用します。ポートを変更するには、オプションでタイプを指定します。

gmail で動作する小さな例を次に示します。

var nodemailer = require('nodemailer');

// Create a SMTP transport object
var transport = nodemailer.createTransport("SMTP", {
        service: 'Gmail',
        auth: {
            user: "test.nodemailer@gmail.com",
            pass: "Nodemailer123"
        }
    });

console.log('SMTP Configured');

// Message object
var message = {

    // sender info
    from: 'Sender Name <sender@example.com>',

    // Comma separated list of recipients
    to: '"Receiver Name" <nodemailer@disposebox.com>',

    // Subject of the message
    subject: 'Nodemailer is unicode friendly ✔', 

    // plaintext body
    text: 'Hello to myself!',

    // HTML body
    html:'<p><b>Hello</b> to myself <img src="cid:note@node"/></p>'+
         '<p>Here\'s a nyan cat for you as an embedded attachment:<br/></p>'
};

console.log('Sending Mail');
transport.sendMail(message, function(error){
  if(error){
      console.log('Error occured');
      console.log(error.message);
      return;
  }
  console.log('Message sent successfully!');

  // if you don't want to use this transport object anymore, uncomment following line
  //transport.close(); // close the connection pool
});
于 2014-04-19T18:01:13.287 に答える
5

おそらく、Windowsファイアウォールまたはウイルス対策が発信アクセスを妨げています。nodemailer デバッグ メッセージを有効にしてみてください。

デバッグを有効にする

var nodemailer = require("nodemailer"),
  transport = nodemailer.createTransport('direct', {
    debug: true, //this!!!
  });

transport.sendMail({
    from: "Fred Foo ✔ <foo@blurdybloop.com>", // sender address
    to: "******@gmail.com", // list of receivers
    subject: "Hello ✔", // Subject line
    text: "Hello world ✔", // plaintext body
    html: "<b>Hello world ✔&lt;/b>" // html body
}, console.error);
于 2014-04-11T15:10:07.130 に答える
0

設定すると、メールを送信できます。 https://www.google.com/settings/security/lesssecureapps これは私のために働いた

于 2015-06-03T08:59:30.057 に答える
0

あなたに代わって電子メールを転送する電子メール サーバーである SMTP サーバーが必要です。したがって、Haraka のような独自の SMTP サーバーをセットアップするか、資格情報を Nodemailer に提供して、Gmail、MSN、Yahoo などに接続します。私も NodeJs の学習を開始し、プロジェクトにメール機能を含めようとしましたが、これは私が直面した同じ問題でした。

于 2015-02-09T11:19:31.603 に答える