I use imap-simple in node js. I want retrieve sent mailbox of gmail. My code is like below:
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
});
});
}
if I call getSent method as below
this.getSent(['ALL'], response => {
});
I get the below error 'Error: Unknown Mailbox: SENT (Failure)'
I try connection.openBox('[Gmail]/Sent Mail')
, but i get the similar error as
'Error: Unknown Mailbox: [Gmail]/Sent Mail (Failure)'
I use gmail.