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
- reply_to – list of addresses for changing email’s reply-to field, default None
- check_names – all recipients are checked if the email address is recognized on True, default False
- Returns: True if there were no errors
Examples
method set_object_property
Set the property of any object.
This is a utility keyword for Robot Framework syntax to set object property values.
Parameters
- object_instance – object instance to set the property
- property_name – property name to set
- value – value to set
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