Free cookie consent management tool by TermsFeed MS Outlook Java Module [Appian RPA v9.10]
Page not found in the selected version; redirected to the home page.
MS Outlook Java Module
The capabilities described on this page are included in Appian's standard capability tier. Usage limits may apply.

The MS Outlook module allows you to use Microsoft Outlook in your robotic task. Using this module, your robotic task can view and reply to emails, download email attachments, and even create and send new emails.

Prerequisites

To use the module, ensure you've completed the following prerequisites:

  • Include the module dependency in the pom.xml.
  • Install the Microsoft Outlook client on your host machine.
  • Ensure you have a valid email account configured on your host machine.
  • Download the Jacob COM Bridge library to your host machine. Note that this library only applies to 64-bit systems. Rename the downloaded .dll file to jacob-1.18-x64.dll and place it in the same directory as the AppianRPAagent.exe utility.

Using the MS Outlook module

The IJidokaOutlook interface contains the objects, methods, and properties the Appian robotic task needs to interact with Outlook. This interface was developed using Outlook Visual Basic for Applications (VBA), so the elements created from the interface implement elements defined in the Outlook VBA object model.

To instantiate the IJidokaOutlook interface, use the following code snippet:

1
IJidokaOutlook outlook = IJidokaOutlook.getInstance(this);

Where this refers to the class that implements the IRobot interface.

Once the interface is initialized, you can begin managing folders in Outlook using the IOlFolderManager interface, or managing new and existing emails in Outlook using the IOlMailManager interface.

Managing folders in Outlook

In the Outlook VBA object model, a folder is represented by a folder object. In Appian RPA, folder objects are represented by the IOlFolder interface.

To get an instance of a folder, you'll use the IOlFolderManager interface. The IOlFolderManager interface provides methods for managing the folders in an Outlook account on your host machine. The most commonly used methods are listed below.

List all folders

The getAllFolderList() method returns a list of IOlFolder objects and their location in the Outlook account. As one of the first commonly used methods, invoking the getAllFolderList() method allows you to validate your access to the configured account and view all available folders.

1
2
3
4
5
server.info("Show Folders:");
List<IOlFolder> foldersList = outlook.getOlFolderManager().getAllFoldersList();
for (IOlFolder folder : foldersList) {
    server.info("Folder Path <" + folder.getFolderPath()+">");
}

To locate a list of subfolders, use the getFolders() method of the IOlFolder object. This method allows you to get a list of folders contained in the specified folder object.

To search for a list of folders, use the findMailFolder() method of the IOlFolderFW object. The IOlFolderFW object is used to search for instances of IOlFolder. This method returns one or more objects that match the criteria specified by the IOlFolderFW object.

1
2
3
4
5
6
7
8
9
IOlFolderFW criteria = new OlFolderFW();
criteria.setFolderPath("\\\\myaccount@mycompany.com POP");
          
List<IOlFolder> folderList = outlook.getOlFolderManager().findMailFolder(criteria);
IOlFolder mainFolder = folderList.get(0);
          
for (IOlFolder folder : mainFolder.getFolders()) {
    server.info("- " + folder.getFolderPath());
}

List emails from a folder

The getMailList() method returns a list of emails from a specified folder. The objects listed will be of type IOlMailItem, which represents an email.

1
2
3
4
5
6
7
8
9
IOlFolderFW criteria = new OlFolderFW();
criteria.setFolderPath("\\\\myaccount@mycompany.com POP\\Inbox");
List<IOlFolder> folderList = outlook.getOlFolderManager().findFolder(criteria);
         
List<IOlMailItem> mailList = outlook.getOlFolderManager().getMailList(folderList.get(0).getEntryID());
         
for (IOlMailItem mailItem : mailList) {
    server.info("Mail Subject <"+mailItem.getSubject()+">");
}

For a full list of methods available from the IOlFolderManager interface, see the Javadocs.

Managing emails in Outlook

In the Outlook VBA object model, an email is represented by a mailItem object. In Appian RPA, mailItem objects are represented by the IOlMailItem interface.

The IOlMailItem object contains information about a specific email, such as the subject line, sender, recipient, creation time, and more. The properties of the object are based on the VBA MailItem object.

To print the properties of the IOlMailItem object, use the following code snippet:

1
2
3
4
5
6
7
8
9
10
11
12
List<IOlMailItem> mailList = outlook.getOlFolderManager().getMailList(folderEntryId);
                  
for (IOlMailItem mailItem : mailList) {
    server.info("Mail Subject <"+mailItem.getSubject()+">");
    server.info("     Sender <"+mailItem.getSenderEmailAddress()+">");
    server.info("     To <"+mailItem.getTo()+">");
    server.info("     CC <"+mailItem.getCc()+">");
    server.info("     BCC <"+mailItem.getBcc()+">");
    server.info("     HtmlBody <"+mailItem.getHtmlBody()+">");
    server.info("     Body <"+mailItem.getBody()+">");
    server.info("     CreationTime <"+mailItem.getCreationTime()+">");
}

To interact with IOlMailItem objects, you'll use the IOlMailManager interface. The methods in this interface allow you to do the following:

Method Description
showMail() Open an email.
closeMail() Close an email.
downloadAttachments() Download file attachments from an email.
saveMail() Save an email to a folder.
move() Move an email to a different folder.
createMail() Create a new email.
sendMail() Send an email.
replyMail() Reply to an email. Use replyAllMail() to reply to all email recipients.
forward() Forward an email.

Open an email

Use the showMail() method to open an email on the screen

1
outlook.getOlMailManager().showMail(mailItem);

Close an email

Use the closeMail() method to close an email on the screen.

1
outlook.getOlMailManager().closeMail(mailItem.getEntryID(),EInspectorClose.SAVE);

Download attached files

Use the downloadAttachments() method to download file attachments from an email.

In the following example, the attachments are saved in a temporary directory that is deleted at the end of the execution.

1
2
3
4
5
6
7
IOlMailItem mailItem = mailList.get(0);
File directory = FileUtil.createTempDirectory();
outlook.getOlMailManager().downloadAttachments( mailItem, directory.getAbsolutePath());
         
for (File fileDownloaded : directory.listFiles()) {
    server.info(String.format("Downloaded file %s", fileDownloaded.getAbsolutePath()));
}

Save an email

Use the saveMail() method to save an email to a specified file path.

In the following example, the email is saved in a temporary file.

1
2
3
4
File directory = FileUtil.createTempDirectory();
File messageFile = FileUtils.getFile(directory, mailItem.getSubject()); 
outlook.getOlMailManager().saveMail(mailItem, messageFile.getAbsolutePath());
server.info(String.format("Downloaded Message to %s",   messageFile.getAbsolutePath()));

Move an email

Use the move() method to move an email between two folders. This method requires two parameters: the IOlMailItem object and a reference to the target folder.

1
2
3
4
5
IOlFolderFW destFolderCriteria = new OlFolderFW();
destFolderCriteria.setFolderPath("\\\\myaccount@mycompany.com POP\\Inbox\\destFolder");
List<IOlFolder> folderDestList = outlook.getOlFolderManager().findFolder(destFolderCriteria);
IOlFolder target = folderDestList.get(0);
outlook.getOlMailManager().move(mailItem, target);

Create an email

Use the createMail() method to create a new email. By default, created emails are stored in the drafts folder. This method returns an IOlMailItem object.

In the following example, an email is created and files are attached. After, the window is closed.

1
2
3
4
5
6
7
8
9
10
IOlMailItem newMail = new OlMailItem();
newMail.setSubject("Subject for IJidokaOutlook mail");
newMail.setTo("toAccount@myCompany.com");
newMail.setCc("ccAccount@myCompany.com");
newMail.setBody("Body for IJidokaOutlook mail");
IOlMailItem createdMail = outlook.getOlMailManager().createMail(newMail, true);
         
outlook.getOlMailManager().addAttachmets(createdMail, "C:\\temp\\attachment.pdf");
 
outlook.getOlMailManager().closeMail(createdMail.getEntryID(),EInspectorClose.SAVE);

Send an email

Use the sendMail() method to send a new email created from the createMail() method.

The following example is similar to the createMail() method example; however, instead of closing the window, the email is sent.

1
2
3
4
5
6
7
8
9
10
11
IOlMailItem newMail = new OlMailItem();
newMail.setSubject("Subject for IJidokaOutlook mail");
newMail.setTo("toAccount@myCompany.com");
newMail.setCc("ccAccount@myCompany.com");
newMail.setBody("Body for IJidokaOutlook mail");
IOlMailItem createdMail = outlook.getOlMailManager().createMail(newMail, true);
         
outlook.getOlMailManager().addAttachmets(createdMail, "C:\\temp\\attachment.pdf");
 
outlook.getOlMailManager().sendMail(createdMail);

Reply to an email

Use the replyMail() method to reply to an email.

1
outlook.getOlMailManager().replyMail(mailItem, "This is a reply");

To reply to all recipients on the email, use the replyAllMail() method.

1
outlook.getOlMailManager().replyAllMail(mailItem, "This is a reply");

Forward an email

Use the forward() method to forward an email. You must add the destination address before executing this method.

1
2
3
4
5
6
IOlMailItem mailItem = mailList.get(0);
 
mailItem.setTo("forwardAccount@myCompany.com");
mailItem.setCc("");
         
outlook.getOlMailManager().forward(mailItem, "This is a Forward");

MS Outlook Java Module

FEEDBACK