【发布时间】:2023-04-10 22:14:01
【问题描述】:
我有一个联系表格,我可以使用 loopback3 将数据保存在数据库中。我还需要发送电子邮件,因此我为此模块添加了电子邮件连接器,但我只能发送邮件中的静态值。如何获取contact.js文件中的动态值并通过电子邮件发送。
contact.json
{
"name": "contact",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"id": {
"type": "number"
},
"name": {
"type": "string",
"required": true
},
"email": {
"type": "string",
"required": true
},
"subject": {
"type": "string",
"required": true
},
"message": {
"type": "string",
"required": true
},
"inserted_date": {
"type": "string"
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
contact.js
'use strict';
const app = require('../../server/server');
module.exports = function(Contact) {
Contact.afterRemote('create', function(context, remoteMethodOutput, next) {
next();
Contact.app.models.Email.send({
to: 'lakshmipriya.l@company.com',
from: 'lakshmipriya.l@gmail.com',
subject: 'my subject',
text: 'my text',
html: 'my <em>html</em>'
}, function(err, mail) {
console.log('email sent!');
cb(err);
});
});
};
如何发送带有动态值的电子邮件,谁能告诉我如何获取contact.json 值并发送到contact.js 文件。
【问题讨论】:
标签: javascript email loopbackjs strongloop nodemailer