// ----------------------------------------------------------------
// Step: saveAttachments
// ----------------------------------------------------------------
GLOBAL.step({
saveAttachments: function(ev, sc, st) {
var rootData = sc.data;
ctx.workflow('saveAttachments', '5290af0c-8449-4755-8416-76779ebed4b3');
// Save the attachments from the selected emails
// Initializes “Microsoft Outlook” application.
ctx.outlook.init();
var mails = [];
var i, j, path, filename, attachments, noAttachments;
// Resets the working mails list.
ctx.outlook.mail.resetMailCollection();
// Search the body of email for a keyword. Other criteria are also available.
ctx.outlook.mail.searchByCriteria({
//fromEmail: "",
//subject: "",
//sender: "",
textDescription: "%test%",
//read: 0,
//hasAttachment: 0,
//date: {after : new Date("MM/JJ/AAAA"),before : new Date("MM/JJ/AAAA")},
//maxRow: 10
dontThrowExceptionIfNoMailFound: true
});
// Get the list of mail information for the mails that fit the criteria.
mails = ctx.outlook.mail.getFilteredTable();
// Build the working mails list by retrieving each mail.
if (mails.length) {
for (i = 0; i < mails.length; i++) {
ctx.outlook.mail.retrieveMail({
EntryID: mails[i]['EntryID'],
StoreID: mails[i]['StoreID']
});
}
// Display some info about each email.
ctx.log("---------------------------------------------------------");
for (i = 0; i < ctx.outlook.mail.getCollectionLength(); i++) {
ctx.log("Mail no: " + i);
ctx.log("From: " + mails[i]['Sender']);
ctx.log("Subject: " + ctx.outlook.mail.getSubject(i));
ctx.log("---------------------------------------------------------");
// Here we start the procedure of downloading the attachments in the email (if they exist).
// Get the number of attachments for each email.
noAttachments = ctx.outlook.mail.getAttachmentsCount(i);
// Get the name of the attachments.
attachments = ctx.outlook.mail.getAttachmentsName(i);
// Download the attachments if they exist.
if (noAttachments > 0) {
// Save each attachment separately.
for (j = 0; j < noAttachments; j++) {
filename = attachments[j];
path = ctx.options.path.log + "\\" + filename;
ctx.outlook.mail.attachmentSave(i, path, {
AttachmentName: filename
});
ctx.log('File downloaded: ' + filename);
}
}
}
}
// Ends “Microsoft Outlook” application.
ctx.outlook.end();
sc.endStep(); // end Scenario
return;
}
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
28 | |
27 | |
14 | |
13 | |
12 | |
11 | |
10 | |
7 | |
7 | |
6 |