
function sendBasicMail() {
// Initializes “Microsoft Outlook” application.
ctx.outlook.init();
// Creates a basic mail.
ctx.outlook.mail.create({To:'name@company.com', Subject:'Test mail from SAP', Body:'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'});
try {
// Sends the mail.
var res = ctx.outlook.mail.send(0);
} catch (err) {
ctx.log("Sending of “Microsoft Outlook” mail in failure (" + err.description + ").");
return e.error.KO;
}
// Ends “Microsoft Outlook” application.
ctx.outlook.end();
}
function sendMailFromAnotherStore() {
ctx.outlook.init();
ctx.outlook.mail.create( {
To:'example@sap.com,',
Subject:'[OUTLOOK LIBRARY TEST] - from another store',
Body:'[OUTLOOK LIBRARY TEST] - Body from another store'
});
ctx.outlook.mail.sendUsingAccount(0, 'example@sap.eu');
ctx.outlook.end();
}

function moveMailInAnotherStore() {
var mails = [];
var i = 0;
ctx.outlook.init();
ctx.outlook.mail.resetMailCollection();
ctx.outlook.mail.searchByCriteria( {
subject : "Documentation - Wiki - Installation guide - Proxy"
});
mails = ctx.outlook.mail.getFilteredTable();
if (mails.length) {
for (i = 0; i< mails.length; i++) {
ctx.outlook.mail.retrieveMail( {
EntryID : mails[i]['EntryID'], StoreID : mails[i]['StoreID']
});
}
ctx.log("---------------------------------------------------------");
for (i = 0; i< ctx.outlook.mail.getCollectionLength(); i++) {
ctx.log("Mail n°" + i);
ctx.log("From: " + mails[i]['Sender']);
ctx.log("Subject: " + ctx.outlook.mail.getSubject(i));
ctx.log("Importance: " + ctx.outlook.mail.getImportance(i));
ctx.log("---------------------------------------------------------");
}
ctx.outlook.mail.moveToSpecificStore(0, 'example@sap.eu', 'Inbox\\Testu');
}
ctx.outlook.end();
}
function dontThrowException() {
var mails = [];
var i = 0;
ctx.outlook.init();
ctx.outlook.mail.resetMailCollection();
ctx.outlook.mail.searchByCriteria( {
subject : "Narf", dontThrowExceptionIfNoMailFound: true
});
//
mails = ctx.outlook.mail.getFilteredTable();
if (mails.length) {
for (i = 0; i< mails.length; i++) {
ctx.outlook.mail.retrieveMail( {
EntryID : mails[i]['EntryID'], StoreID : mails[i]['StoreID']
});
}
ctx.log("---------------------------------------------------------");
for (i = 0; i< ctx.outlook.mail.getCollectionLength(); i++) {
ctx.log("Mail n°" + i);
ctx.log("From: " + mails[i]['Sender']);
ctx.log("Subject: " + ctx.outlook.mail.getSubject(i));
ctx.log("Importance: " + ctx.outlook.mail.getImportance(i));
ctx.log("---------------------------------------------------------");
}
ctx.outlook.mail.moveToSpecificStore(0, 'example@sap.eu', 'Inbox\\Testu');
}
ctx.outlook.end();
}function replyInsertBody() {
var mails = [];
var i = 0;
ctx.outlook.init();
ctx.outlook.mail.resetMailCollection();
ctx.outlook.mail.searchByCriteria( {
subject : "Test appendBody"
});
//
mails = ctx.outlook.mail.getFilteredTable();
if (mails.length) {
for (i = 0; i< mails.length; i++) {
ctx.outlook.mail.retrieveMail( {
EntryID : mails[i]['EntryID'], StoreID : mails[i]['StoreID']
});
}
ctx.log("---------------------------------------------------------");
for (i = 0; i< ctx.outlook.mail.getCollectionLength(); i++) {
ctx.log("Mail n°" + i);
ctx.log("From: " + mails[i]['Sender']);
ctx.log("Subject: " + ctx.outlook.mail.getSubject(i));
ctx.log("Importance: " + ctx.outlook.mail.getImportance(i));
ctx.log("---------------------------------------------------------");
}
ctx.outlook.mail.reply(0);
var index = ctx.outlook.mail.getCollectionLength() -1;
ctx.outlook.mail.appendBody(index, "New body");
ctx.outlook.mail.send(index);
}
ctx.outlook.end();
}
function searchInAnotherAccount() {
var mails = [];
var i = 0;
// Initializes “Microsoft Outlook” application.
ctx.outlook.init();
// Resets the working mails list.
ctx.outlook.mail.resetMailCollection();
// Sets a filter to retrieve all unread mails (with max set to 10).
try {
ctx.outlook.mail.search( {
filter : "\"" + "urn:schemas:httpmail:read" + "\"" + "= 0",
maxRow : 10, storeName : 'example@sap.eu'
});
} catch (ex) {
ctx.log("no email found");
return e.error.KO;
}
// Retrieves the result of search.
mails = ctx.outlook.mail.getFilteredTable();
if (mails.length) {
// Build the working mails list by retrieving the detail of each mail.
for (i = 0; i< mails.length; i++)
try {
ctx.outlook.mail.retrieveMail( {
EntryID : mails[i]['EntryID'], StoreID : mails[i]['StoreID']
});
} catch (ex) {
ctx.log("could not retrieve an email");
}
// Displays some information of each mail in debug prints.
ctx.log("---------------------------------------------------------");
for (i = 0; i< ctx.outlook.mail.getCollectionLength(); i++) {
ctx.log("Mail n°" + i);
ctx.log("From: " + mails[i]['Sender']);
ctx.log("Subject: " + ctx.outlook.mail.getSubject(i));
ctx.log("Importance: " + ctx.outlook.mail.getImportance(i));
ctx.log("---------------------------------------------------------");
}
}
// Ends “Microsoft Outlook” application.
ctx.outlook.end();
}
function searchInFolder() {
var mails = [];
var i = 0;
// Initializes “Microsoft Outlook” application.
ctx.outlook.init();
// Resets the working mails list.
ctx.outlook.mail.resetMailCollection();
// Sets a filter to retrieve all unread mails (with max set to 10).
try {
ctx.outlook.mail.search( {
filter : "urn:schemas:httpmail:subject like '%remboursement%' AND urn:schemas:httpmail:read = 0 ",
maxRow : 10, folderName : 'Mutuelle'
});
} catch (ex) {
ctx.log("no email found");
return e.error.KO;
}
// Retrieves the result of search.
mails = ctx.outlook.mail.getFilteredTable();
if (mails.length) {
// Build the working mails list by retrieving the detail of each mail.
for (i = 0; i< mails.length; i++)
try {
ctx.outlook.mail.retrieveMail( {
EntryID : mails[i]['EntryID'], StoreID : mails[i]['StoreID']
});
} catch (ex) {
ctx.log("could not retrieve an email");
}
// Displays some information of each mail in debug prints.
ctx.log("---------------------------------------------------------");
for (i = 0; i< ctx.outlook.mail.getCollectionLength(); i++) {
ctx.log("Mail n°" + i);
ctx.log("From: " + mails[i]['Sender']);
ctx.log("Subject: " + ctx.outlook.mail.getSubject(i));
ctx.log("Importance: " + ctx.outlook.mail.getImportance(i));
ctx.log("---------------------------------------------------------");
}
}
// Ends “Microsoft Outlook” application.
ctx.outlook.end();
}
function sendMailWithImageInBody() {
var imagePath = "C:\\ProgramData\\SAP\\Intelligent RPA\\SDK 2.0.2.6\\templates\\resources\\bmp64\\agent128.png";
ctx.outlook.init();
ctx.outlook.mail.create( {
To:'example@sap.com', Subject:'Test email with image'
});
var body_text = '<!DOCTYPE html>';
body_text += '<html>';
body_text += ' <head>';
body_text += '<title>HTML img Tag</title>';
body_text += '</head>';
body_text += '<body>';
body_text += '<img src="data:image/png;base64,' + ctx.base64.encodeStream(ctx.fso.file.read(imagePath, e.file.encoding.Binary)) + '">';
body_text += '</body>';
body_text += '</html>';
try {
ctx.outlook.mail.setBodyHtml(0, body_text);
var res = ctx.outlook.mail.send(0);
} catch (err) {
ctx.log("error : " + err);
}
ctx.outlook.end();
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 4246 | |
| 3359 | |
| 2603 | |
| 2153 | |
| 1983 | |
| 1255 | |
| 1164 | |
| 1122 | |
| 1100 |