We have an automation that requires to loop through the outlook folder, read each details and save each email as *.MSG file.
So far what we are able to achieve is to retrieve the emails from a folder (Mail Collection) and loop through by index to get the details. We are able to find a Save method under the Mail Item proxy. This runs smoothly, no runtime error, but we can seems to find the saved email.
Is there a default folder where the email is being saved and download, is that folder can be altered to cater the process needs?
@rnikkoprado Save actually saves the mail into Outlook. You want to save it to disk. To do that, you need the SaveAs method. This exists on the actual Outlook MailItem. You can access this from ObjectExplorer.
Select your "mailItem" proxy object in Object Explorer,
Click the icon in the upper right area of the window labelled "Explore Component Properties".
Locate the "OutlookMail" item and select it.
Select the SaveAs method from this item and drag it into your automation.
You can now click the are from step 2, however now the icon will be labelled "Explore Components" to return to the previous view.
The SaveAs method takes two parameters.
The first is the path to where and what file name you wish to save the messages as (C:\Temp\MyMessage.msg" for example).
The second is an enum value corresponding to the list below. The easiest way is just to pass it an integer corresponding to the option you prefer (likely a 3).
@ThomasSasnett If you would like to select the Save As type instead of passing it an an integer, you may do so with a Jump Label. The method accepts an object, however the exact type is Microsoft.Office.Interop.Outlook.OlSaveAsType. To get this in your automation, you can create a Jump Label and add a parameter. Then select Browse on the data type column and select Microsoft.Office.Interop.Outlook.OlSaveAsType as shown in the screenshot. Now, when you jump to this label, you can select the type from a drop-down list rather than having to know the exact numerical value.
@ThomasSasnett Hello Thomas, Just a follow-up, the solution you suggested is working but currently is on intermitent and we are encountering Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT)) in the MailItem.SaveAs() method.
What should we do in order to make a consistent run?
Posted: 3 months ago
Posted: 17 Aug 2022 10:18 EDT
Thomas Sasnett (ThomasSasnett)
Lead Robotics Architect