我在email connector看到要使用电子邮件连接器的环回文档 我在datasources.js中的电子邮件数据源如下:
"emailDataSource": {
"name": "emailDataSource",
"connector": "mail",
"transports":[{
"type":"SMTP",
"host": "stmp.gmail.com",
"secure":true,
"port":50,
"auth":{
"user":"test@gmail.com",
"pass":"pass"
}
}]}
我在model-config.json中的配置
"Email":{
"dataSource":"emailDataSource"}
这是我使用远程方法对模型js文件的测试:
MyModel.orderproduct = function(id, email, cb){
MyModel.app.models.Email.send({
to: email,
from: 'test@gmail.com',
subject: 'test subject',
text : 'my text',
html : 'my <em> html </em>'
}, function(err, mail){
console.log('email sent!' + mail);
cb(err);
});
}
MyModel.remoteMethod('orderproduct',{
accepts:[{arg:'id',type : 'string', required: true},
{arg: 'email', type : 'string', required : true}],
http: {path : '/product/:id', verb : 'get',source: 'query'},
return:{arg : 'res', type : 'Object'}
});
我的请求是我的远程方法的成功状态。但我从邮件连接器组件收到错误:
{"error": {
"statusCode": 500,
"name": "Error",
"message": "connect ETIMEDOUT 125.235.4.59:50",
"errno": "ETIMEDOUT",
"code": "ECONNECTION",
"syscall": "connect",
"address": "125.235.4.59",
"port": 50,
"command": "CONN",
"stack": "Error: connect ETIMEDOUT 125.235.4.59:50\n at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1189:14)"
} }
有人提供一些使用Loopback框架的邮件连接器的高级或教程。 谢谢〜
答案 0 :(得分:0)
问题在于SMTP
服务器的配置。端口号应为465
而不是50
。使用以下配置
"transports": [{
"type": "SMTP",
"host": "smtp.gmail.com",
"secure": true,
"port": 465,
"auth": {
"user": "name@gmail.com",
"pass": "pass"
}
}]
参考:https://loopback.io/doc/en/lb3/Email-connector.html#using-gmail