RPA.Outlook.Application
module RPA.Outlook.Application
class RPA.Outlook.Application.Application
Outlook.Application is a library for controlling the Outlook application.
About Email Filtering
Emails can be filtered according to specification set by Restrict method of the Item class https://docs.microsoft.com/en-us/office/vba/api/outlook.items.restrict.
Couple of examples:
Examples
Robot Framework
Python
For more information, see: https://docs.microsoft.com/en-us/previous-versions/office/developer/office-2007/bb219950(v=office.12
Caveats
This library works on a Windows operating system with UI enabled only, and you must
ensure that you open the app first with Open Application
before running any
other relevant keyword which requires to operate on an open app. The application is
automatically closed at the end of the task execution, so this can be changed by
importing the library with the autoexit=${False} setting.
If youβre running the Process by Control Room through a custom self-hosted Worker service, then please make sure that you enable an RDP session by ticking βUse Desktop Connectionβ under the Step configuration.
If you still encounter issues with opening a document, please ensure that file can be opened first manually and dismiss any alert potentially blocking the process.
Check the documentation below for more info:
- https://robocorp.com/docs/control-room/unattended/worker-setups/windows-desktop
- https://robocorp.com/docs/faq/windows-server-2016
variable APP_DISPATCH
variable ROBOT_LIBRARY_DOC_FORMAT
variable ROBOT_LIBRARY_SCOPE
property app
method close_document
Close the active document and app (if open).
- Parameters: save_changes β Enable changes saving on quit. (False by default)
method get_emails
Get emails from a specified email folder. Can be used to save attachments.
Parameters
- account_name β needs to be given if there are shared accounts in use, defaults to None
- folder_name β target folder where to get emails from, default Inbox
- email_filter β how to filter email, default no filter, ie. all emails in folder
- save_attachments β if attachments should be saved, defaults to False
- attachment_folder β target folder where attachments are saved, defaults to current directory
- sort β if emails should be sorted, defaults to False
- sort_key β needs to be given if emails are to be sorted
- sort_descending β set to False for ascending sort, defaults to True
- Returns: list of emails (list of dictionaries)
method mark_email_as_read
Mark email βreadβ property. Can be used to mark email as unread.
Parameters
- email β target email
- read β True marks email as Read, False as Unread
method move_emails
Move emails from source folder to target folder.
Use of βaccount_nameβ is recommended if there are shared accounts in use.
Parameters
- account_name β needs to be given if there are shared accounts in use, defaults to None
- source_folder β folder where source emails exist
- email_filter β how to filter email, default no filter, ie. all emails in folder
- target_folder β folder where emails are moved into
- mark_as_read β mark emails as read after move, defaults to True
- Returns: True if move operation was success, False if not
Python example.
Robot Framework example.
method open_application
Open the application.
Parameters
- visible β Show the window on opening. (False by default)
- display_alerts β Display alert popups. (False by default)
method quit_application
Quit the application.
- Parameters: save_changes β Enable to save changes on quit. (False by default)
method save_email_attachments
Save email attachments.
Note. Keyword βGet Emailsβ can be also used to save attachments.
Parameters
- attachments β all attachments from email or single attachment
- attachment_folder β target folder where attachments are saved, defaults to current directory
- overwrite β overwrite existing file if True, defaults to False
method send_email
Send email with Outlook
Parameters
- recipients β list of addresses
- subject β email subject
- body β email body
- html_body β True if body contains HTML, defaults to False
- attachments β list of filepaths to include in the email, defaults to []
- save_as_draft β email is saved as draft when True
- cc_recipients β list of addresses for CC field, default None
- bcc_recipients β list of addresses for BCC field, default None
- Returns: True if there were no errors
Examples
method wait_for_email
Wait for email matching criterion to arrive into mailbox.
Parameters
- criterion β email filter to wait for, defaults to ββ
- timeout β total time in seconds to wait for email, defaults to 5.0
- interval β time in seconds for new check, defaults to 1.0
- Returns: list of messages or False
Possible wait criterias are: SUBJECT, SENDER and BODY