ad_oauth2
Version:
50 lines (35 loc) • 1.68 kB
JavaScript
const token = require('./getToken');
function yunus(){
console.log("export oldu");
}
async function connectAndChangeAllEmails(){
let exchangeServiceUrl = 'https://outlook.office365.com/Ews/Exchange.asmx';
//let searchMask = 'hasattachments:yes and from:yunus.yildiz@easytr.com and received:today';
let searchMask = 'hasattachments:yes and from:yunus.yildiz@easytr.com';
// get acces token by method written above in part 2
const emailAccessToken = await token.getEmailAccessToken();
const ews = require('ews-javascript-api');
const service = new ExchangeService(ews.ExchangeVersion.Exchange2013);
// use emailAccesToken
service.Credentials = new OAuthCredentials(emailAccessToken);
service.Url = new ews.Uri(exchangeServiceUrl);
const mailInbox = await ews.Folder.Bind(service, ews.WellKnownFolderName.Inbox);
const loadPageSize = 1000; // 1 means load last email according to filter
const view = new ews.ItemView(loadPageSize);
view.PropertySet = new ews.PropertySet(ews.BasePropertySet.FirstClassProperties);
let mailItems;
// hasattachment:yes
// isread:false
// received:today or received:[date]
mailItems = await mailInbox.FindItems(searchMask, view);
console.log(`Emails were found before processing: ${mailItems.Items.length}`);
for (const item of mailItems.Items) {
// mark mail.item as read
// item.IsRead = true;
// await item.Update(1);
// Do what you want
}
return mailItems.Items.length;
}
module.exports.listEmail = connectAndChangeAllEmails;
module.exports.selam = yunus ;