javascript - 如何从外部 nodemailer 传输访问 info.response 对象
问题描述
我正在尝试创建已发送邮件的日志,包括其他一些详细信息,并且需要info.response
从节点中的邮件传输器访问对象,我尝试了很多事情,包括尝试将其公开info.response
为全局变量,但我似乎无法访问它. 我想使用传输器发送邮件,然后info.response
在 log.txt 文件的同一行中记录一些条目详细信息和代码。在resInfo
传输器外部无法访问,并且clientReminderCandidates[x][1]
无法从传输器内部访问阵列。
index.js
gm.clientReminders();
// clientReminderCandidates made available
if (clientReminderCandidates.length != 0) {
for (x = 0; x < clientReminderCandidates.length; x++) {
const clientReminders = require('./sendClientReminders.js')
clientReminders.sendRemindClient();
const updateReminders = require('./updateClientReminderSent.js')
updateReminders.updateClientReminder();
}
}
else { console.log("No client reminders to update") }
sendClientReminders.js
module.exports = {
sendRemindClient: function () {
var fs = require('fs');
fs.appendFile('logs/logs.txt', 'LOG Reminder sent to ' + clientReminderCandidates[x][10] + ' ' + resInfo + ' \r\n', function (err) { // cannot access resInfo outside transporter
if (err) throw err;
console.log('Reminder Sent and Logged!');
});
transporter.sendMail(mailOptions, function (error, info) {
resInfo = info; // I tried to reassign the `info` var from the transport function above
if (error) {
console.log(resInfo); // but this does not pull in the `info` var
console.log(resInfo);
console.log(info.response); // I need to use this in the top function @ resInfo.
transporter.close();
} else {
console.log(error);
console.log(clientReminderCandidates); // array is available
console.log(clientReminderCandidates[x][1]); // cannot access these objects undefined
console.log('Reminder Sent and Logged!');
transporter.close();
}
});
}
}
如何访问 info.response 以便在fs.appendfile
函数中使用它来构建包含响应代码的日志条目?
解决方案
推荐阅读
- powershell - 无法使用 Powershell 从远程服务器获取 IIS 状态
- python - 在python中生成和写入大于系统RAM的文件
- android - Android:为 VectorDrawable 设置动画会导致 lg g3 出现奇怪的问题
- flutter - 颤动医生命令,但没有任何反应
- c - Malloc 被意外中断中断
- reactjs - TypeScript React setState 不起作用
- python - 在 Python 中查找素数(模数运算符有问题?)
- asp.net - 使用过滤器 (EnumDropDownListFor) 设置 MVC ASP.NET 从详细信息返回到索引页面
- android - 如何从动态创建中查找编辑文本框和微调器 任何人都可以
- javascript - NodeJS - FOREACH 函数不会运行所有元素并停止