这类似于this question,但是我试图连接到这个虚假的smtp-server
https://www.npmjs.com/package/smtp-sink
我使用npm i smtp-sink
和smtp-sink
运行此服务器,看起来很好
以下是我配置数据源的方法:
"emailDataSource": {
"connector": "mail",
"transports": [{
"type": "smtp",
"host": "localhost",
"secure": false,
"port": 1025,
"tls": {
"rejectUnauthorized": false
}
}]
}
并通过端点发送电子邮件:(此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);
});
但是,我现在收到以下错误
{
"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)"
}
}
答案 0 :(得分:0)
请查看我的示例,了解如何发送电子邮件:https://github.com/strongloop/loopback-faq-email
至于NPM套餐,我从未使用它,所以我无法帮助你。