Javascript 如何检索;“发送”;imap simple中的邮箱
我在NodeJS中使用。 我想找回gmail的邮箱。我的代码如下:Javascript 如何检索;“发送”;imap simple中的邮箱,javascript,node.js,imap,Javascript,Node.js,Imap,我在NodeJS中使用。 我想找回gmail的邮箱。我的代码如下: getSent(searchCriteria: string[], callBack: any) { imaps.connect(this.imapConfig).then(function (connection) { return connection.openBox('SENT').then(function () { var fetchOptio
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]/sentmail')
,但得到的错误与
'错误:未知邮箱:[Gmail]/已发送邮件(失败)
我使用gmail我使用GetBox方法获取所有文件夹名称。然后我看到文件夹名称是阿塞拜疆语的
connection.getBoxes().then(response => {
var r = response;
});
问题在于谷歌设置。我用阿塞拜疆语用谷歌。如果使用谷歌不同的语言,文件夹名称会自动翻译成该语言。我把谷歌语言改成英语,问题解决了。这对我很有用。谢谢大家
我使用[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
});
});
}
我可能错了,但我模糊地记得Gmail中发送文件夹的名称是“发送电子邮件”,而不是“发送邮件”/“发送”,你试过了吗?我已经试过“发送邮件”和“发送”,但如果你解决了你自己的问题,我会遇到类似的错误-请自己发布答案!亲爱的@arnt我的谷歌账户使用的是阿塞拜疆语,因此“发送框”的名字翻译成了阿塞拜疆语。如果谷歌账户使用阿塞拜疆语,邮箱名称将是[Gmail]/Göndərilənlər。或者将谷歌的语言改为英语,那么sentbox的名字将是[Gmail]/用谷歌的语言发送邮件。谢谢@leonheess。我已经发布了答案,但我现在不能接受自己的答案,我会在明天接受