EmailJS两次调用回调

时间:2018-09-01 17:00:44

标签: node.js email

我使用emailjs在nodejs中发送邮件,但问题是回调被调用了两次,输出是:

mail test
sending status...

err { Error: no connection has been established
    at module.exports (D:\tests\node_modules\emailjs\smtp\error.js:33:14)
    at SMTP.send (D:\tests\node_modules\emailjs\smtp\smtp.js:377:5)
    at SMTP.command (D:\tests\node_modules\emailjs\smtp\smtp.js:414:8)
    at SMTP.helo (D:\tests\node_modules\emailjs\smtp\smtp.js:428:8)
    at ehlo (D:\tests\node_modules\emailjs\smtp\smtp.js:635:11)
    at caller (D:\tests\node_modules\emailjs\smtp\smtp.js:76:12)
    at command (D:\tests\node_modules\emailjs\smtp\smtp.js:507:5)
    at caller (D:\tests\node_modules\emailjs\smtp\smtp.js:76:12)
    at response (D:\tests\node_modules\emailjs\smtp\smtp.js:397:5)
    at caller (D:\tests\node_modules\emailjs\smtp\smtp.js:76:12) code: 6, smtp: undefined, previous: null }
message Message {
  attachments: [],
  alternative:
   { data: '<html>i <i>hope</i> this works! </html>',
     alternative: true,
     charset: 'utf-8',
     type: 'text/html',
     inline: true },
  header:
   { 'message-id': '<1535820394667.0.14872@Ali-pc>',
     date: 'Sat, 01 Sep 2018 19:46:34 +0300',
     from: 'portal@hudumakenya.go.ke',
     to: 'hamisi.yusuf@ekenya.co.ke',
     subject: '=?UTF-8?Q?testing_emailjs?=' },
  content: 'text/plain; charset=utf-8',
  text: 'i hope this works' }
sending status...

err { Error: timedout while connecting to smtp server
    at module.exports (D:\tests\node_modules\emailjs\smtp\error.js:33:14)
    at TLSSocket.timedout (D:\tests\node_modules\emailjs\smtp\response.js:65:5)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:106:13)
    at TLSSocket.emit (events.js:208:7)
    at TLSSocket.Socket._onTimeout (net.js:410:8)
    at ontimeout (timers.js:498:11)
    at tryOnTimeout (timers.js:323:5)
    at Timer.listOnTimeout (timers.js:290:5) code: 4, smtp: undefined, previous: null }
message Message {
  attachments: [],
  alternative:
   { data: '<html>i <i>hope</i> this works! </html>',
     alternative: true,
     charset: 'utf-8',
     type: 'text/html',
     inline: true },
  header:
   { 'message-id': '<1535820394667.0.14872@Ali-pc>',
     date: 'Sat, 01 Sep 2018 19:46:34 +0300',
     from: 'portal@hudumakenya.go.ke',
     to: 'hamisi.yusuf@ekenya.co.ke',
     subject: '=?UTF-8?Q?testing_emailjs?=' },
  content: 'text/plain; charset=utf-8',
  text: 'i hope this works' }

这是我的代码

var server  = email.server.connect({
    user:   "", 
    password:"", 
    host:   "", 
    tls: {ciphers: "SSLv3"},
    ssl: false,
    port: 587,
    authentication: [ 'LOGIN' ],
    // timeout: 20000
 });

 var message    = {
    text:   "i hope this works", 
    from:   "portal@hudumakenya.go.ke", 
    to:     "hamisi.yusuf@ekenya.co.ke",
    subject:    "testing emailjs",
    attachment: [
        {
            data: "<html>i <i>hope</i> this works! </html>",
            alternative: true
        }
    ] 
 };
 console.log('mail test');
 server.send(message, function(err, message) { 
     console.log('sending status...'); 
     console.log(); 
     console.log('err', err); 
     console.log('message', message);
});

console.log('mail test')只是检查文件是否执行了两次,但事实证明文件仅被调用了一次,但回调被调用了两次。更奇怪和令人困惑的事实是,即使它产生了这些错误,仍然在发送电子邮件,任何人都可以在这里帮助我,因为这现在使我发疯,谢谢。

编辑

正在使用的软件包为emailjs

0 个答案:

没有答案