How do I connect to a fake SMTP server using Loopback

℡╲_俬逩灬. 提交于 2019-12-25 14:45:51

问题


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

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

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

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)

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:


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

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



来源:https://stackoverflow.com/questions/27536122/how-do-i-connect-to-a-fake-smtp-server-using-loopback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!