如何使用Loopback连接到虚假的SMTP服务器

时间:2022-06-24 18:09:47

This similar to to this question, but intstead I am trying to connect to this fake smtp-server

这类似于这个问题,但我试图连接到这个假的smtp服务器

https://www.npmjs.com/package/smtp-sink

https://www.npmjs.com/package/smtp-sink

I run this server using npm i smtp-sink and smtp-sink and it seems fine

我使用npm i smtp-sink和smtp-sink运行这个服务器,看起来很好

Here is how I have configured my datasource:

以下是我配置数据源的方法:

  "emailDataSource": {
    "connector": "mail",
    "transports": [{
      "type": "smtp",
      "host": "localhost",
      "secure": false,
      "port": 1025,
      "tls": {
        "rejectUnauthorized": false
      }
    }]
  }

and sending the email through an endpoint as such: (this 9is inside a remote method)

并通过端点发送电子邮件:(这9是在远程方法内)

var options = {

  to: "bla@bla.com",
  subject: "subject",
  text: "text",
  html: "html"
};

app.models.Email.send(options, function (err, mail) {
  cb(null || err, null || mail);
});

However, I now get the following error

但是,我现在收到以下错误

{
  "error": {
    "name": "Error",
    "status": 500,
    "message": "Data command failed",
    "code": "EENVELOPE",
    "response": "503 Bad sequence: MAIL expected",
    "responseCode": 503,
    "stack": "Error: Data command failed\n    at SMTPConnection._formatError (/Users/admin/Documents/Projects/otogo/otogo-api-server/build/node_modules/loopback/node_modules/nodemailer/node_modules/nodemailer-smtp-transport/node_modules/smtp-connection/src/smtp-connection.js:388:15)\n    at SMTPConnection._actionDATA (/Users/admin/Documents/Projects/otogo/otogo-api-server/build/node_modules/loopback/node_modules/nodemailer/node_modules/nodemailer-smtp-transport/node_modules/smtp-connection/src/smtp-connection.js:909:30)\n    at SMTPConnection.<anonymous> (/Users/admin/Documents/Projects/otogo/otogo-api-server/build/node_modules/loopback/node_modules/nodemailer/node_modules/nodemailer-smtp-transport/node_modules/smtp-connection/src/smtp-connection.js:885:22)\n    at SMTPConnection._processResponse (/Users/admin/Documents/Projects/otogo/otogo-api-server/build/node_modules/loopback/node_modules/nodemailer/node_modules/nodemailer-smtp-transport/node_modules/smtp-connection/src/smtp-connection.js:507:16)\n    at SMTPConnection._onData (/Users/admin/Documents/Projects/otogo/otogo-api-server/build/node_modules/loopback/node_modules/nodemailer/node_modules/nodemailer-smtp-transport/node_modules/smtp-connection/src/smtp-connection.js:357:10)\n    at Socket.emit (events.js:95:17)\n    at Socket.<anonymous> (_stream_readable.js:764:14)\n    at Socket.emit (events.js:92:17)\n    at emitReadable_ (_stream_readable.js:426:10)\n    at emitReadable (_stream_readable.js:422:5)"
  }
}

1 个解决方案

#1


0  

Look at my example here on how to send emails: https://github.com/strongloop/loopback-faq-email

看看我在这里发送电子邮件的例子:https://github.com/strongloop/loopback-faq-email

As for the NPM package, I've never used it so I can't help you there.

至于NPM包,我从来没有用过它,所以我无法帮助你。

#1


0  

Look at my example here on how to send emails: https://github.com/strongloop/loopback-faq-email

看看我在这里发送电子邮件的例子:https://github.com/strongloop/loopback-faq-email

As for the NPM package, I've never used it so I can't help you there.

至于NPM包,我从来没有用过它,所以我无法帮助你。