我正在创建一个在下订单时发送邮件的函数,并且我想获取对用户电子邮件的引用,该电子邮件位于路径为=>的数据库中,以获取用户ID用户发送邮件的数量。如何在我的函数中获取此引用?
我尝试过firebase.database.ref(/Users/${userId}/email
)。val(),admin.database.ref(/Users/${userId}/email
)。val()。但是这些都不起作用。
exports.orderPlaced = functions.database.ref(/Users/{uid}/Bag/Books/{orderId}).onCreate((snapshot, context) => {
const userId = context.params.uid;
const orderid = context.params.orderId;
const refer = firebase.database.ref(/Users/${userId}/email).val();
const mailOptions = {
from: '"abc" <abc@gmail.com>',
to: 'xyz@gmail.com',
subject: 'Order Details',
html: `<p style="font-size: 16px;">${orderId}</p>
<br />
` // email content in HTML
};
try {
mailTransport.sendMail(mailOptions);
console.log('mail send');
}
catch(error) {
console.error('There was an error while sending the email:', error);
}
return null;
});
我想获取用户的电子邮件ID,但得到的错误是在exports.orderPlaced.functions.database.ref上未定义firebase
答案 0 :(得分:1)
您可能会遇到未定义的export.orderPlaced错误,因为firebase使用导出功能来访问文档,该文档在您的代码中是const refer
举一个例子: <h4>User Details</h4>
<table>
<thead>
<tr>
<th>Name </th>
<th> %User.Name%</th>
<th>Mobile number</th>
<th> %User.Mobile%</th>
<th>Email Id</th>
<th>%User.Email%</th>
</tr>
</thead>
<tbody>
<tr>
<td> your name </td>
<td> user name </td>
<td> your mobile </td>
<td> your mobile no </td>
<td> example@gmail.com </td>
<td> User email</td>
</tr>
<tr>
<td> your name </td>
<td> user name </td>
<td> your mobile </td>
<td> your mobile no </td>
<td> example@gmail.com </td>
<td> User email</td>
</tr>
</tbody>
</table>