我在节点js中使用imap-简单。我要找回gmail的邮箱。我的代码如下:
getSent(searchCriteria: string[], callBack: any) {
imaps.connect(this.imapConfig).then(function (connection) {
return connection.openBox('SENT').then(function () {
var fetchOptions = {
bodies: ['HEADER', 'TEXT', ''],
markSeen: false
};
return connection.search(searchCriteria, fetchOptions).then(function (results) {
let mails = results.map(res => {
return {
part: res.parts.find(part => part.which === ''),
attributes: res.attributes
};
});
mails = [].concat(...mails);
mails = mails.map(mail => {
return new Promise((resolve, reject) => {
var id = mail.attributes.uid;
var idHeader = "Imap-Id: " + id + "\r\n";
simpleParser(idHeader + mail.part.body, (error, mail) => {
if (error)
reject(error);
else {
resolve(new Email({
sentDate: mail.date,
from: mail.from.text,
to: mail.to.text,
messageId: mail.messageId,
body: mail.html,
subject: mail.subject
}));
}
});
})
});
Promise.all(mails).then(response => {
callBack({
success: true,
emails: response,
error: undefined
});
}, error => {
callBack({
success: false,
emails: [],
error: error
});
});
}, function (error) {
callBack({
success: false,
emails: [],
error: error
});
});
}, function (error) {
callBack({
success: false,
emails: [],
error: error
});
});
}, function (error) {
callBack({
success: false,
emails: [],
error: error
});
});
}
如果我按下面的方式调用getSent方法
this.getSent(['ALL'], response => {
});
我得到以下错误的错误:未知邮箱:发送(失败)‘
我尝试了connection.openBox('[Gmail]/Sent Mail')
,但是我得到了类似的错误
错误:未知邮箱:Gmail/已发送邮件(失败)‘
我使用gmail。
发布于 2020-01-28 06:43:32
我使用getBoxes方法获得了所有文件夹名。然后我看到文件夹的名字是阿塞拜疆语的。
connection.getBoxes().then(response => {
var r = response;
});
问题出在谷歌的设置上。我用了阿塞拜疆语的谷歌。如果使用google不同的语言,文件夹名就会自动翻译成该语言。我把谷歌语言改成了英语,问题解决了。这对我来说很有效。感谢每个人。
我使用[Gmail]/Sent Mail
.
我的代码的正确版本如下:
getSent(searchCriteria: string[], callBack: any) {
imaps.connect(this.imapConfig).then(function (connection) {
return connection.openBox('[Gmail]/Sent Mail').then(function () {
var fetchOptions = {
bodies: ['HEADER', 'TEXT', ''],
markSeen: false
};
return connection.search(searchCriteria, fetchOptions).then(function (results) {
let mails = results.map(res => {
return {
part: res.parts.find(part => part.which === ''),
attributes: res.attributes
};
});
mails = [].concat(...mails);
mails = mails.map(mail => {
return new Promise((resolve, reject) => {
var id = mail.attributes.uid;
var idHeader = "Imap-Id: " + id + "\r\n";
simpleParser(idHeader + mail.part.body, (error, mail) => {
if (error)
reject(error);
else {
resolve(new Email({
sentDate: mail.date,
from: mail.from.text,
to: mail.to.text,
messageId: mail.messageId,
body: mail.html,
subject: mail.subject
}));
}
});
})
});
Promise.all(mails).then(response => {
callBack({
success: true,
emails: response,
error: undefined
});
}, error => {
callBack({
success: false,
emails: [],
error: error
});
});
}, function (error) {
callBack({
success: false,
emails: [],
error: error
});
});
}, function (error) {
callBack({
success: false,
emails: [],
error: error
});
});
}, function (error) {
callBack({
success: false,
emails: [],
error: error
});
});
}
发布于 2022-11-14 20:34:45
我也有同样的问题,我必须自己想办法:
将connection.openBox('SENT')
替换为connection.openBox('INBOX.Sent')
或connection.openBox('INBOX/Sent')
。
取决于指定的分隔符(。或/或任何其他),您可以通过添加
connection.getBoxes().then(response => {
var r = response;
console.log(r); // if nothing then try console.log(JSON.stringify(r))
});
我希望这能解决你的问题。祝您今天愉快!
https://stackoverflow.com/questions/59930385
复制相似问题