gpt4 book ai didi

javascript - 如何在 imap-simple 中检索 "sent"邮箱

转载 作者:行者123 更新时间:2023-12-01 12:00:40 26 4
gpt4 key购买 nike

我用 imap-simple在 Node js 中。
我想找回已发送的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 .

最佳答案

我使用 getBoxes 方法获得了所有文件夹名称。然后我看到文件夹名称以阿塞拜疆语言出现。

connection.getBoxes().then(response => {
var r = response;
});

问题出在谷歌设置中。我用阿塞拜疆语的谷歌。如果使用 google 不同的语言,文件夹名称会自动翻译成该语言。我将谷歌语言更改为英语,问题解决了。这对我有用。谢谢大家。

enter image description here

我用 [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
});
});
}

关于javascript - 如何在 imap-simple 中检索 "sent"邮箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59930385/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com