Jump to content

How to open email with OutlookEX UDF, actually click email


Go to solution Solved by Abraham,

Recommended Posts

Hello, everyone! I'm thrilled to be part of this AutoIt community.

I apologize for the inconvenience, Mr. Water, but I was wondering if there's a way in your UDF to open an email as if a user were opening it manually?

I'm developing a system for my factory where the user will have numerous emails on various topics. Occasionally, she might want to check some details or even read the email history by herself. Some of these emails might be old, and I don't want to save all the email subjects somewhere only to paste them into the Outlook search box to find them later.

Therefore, I need to actually open the email on the screen. I've been searching for a way to do this, but the only solution I've found so far is to use the item reply function. It works, but it requires the user to discard the email every time, which is not ideal.

Could anyone help me with this? Thank you all in advance.
 

Link to comment
Share on other sites

To display a mail item I would use something like

$oItem.Display

For details see: https://learn.microsoft.com/en-ca/office/vba/api/outlook.mailitem.display

To retrieve the mail object to display use _OL_ItemFind or retrieve the currently selected item using

$oItem = $oOutlook.ActiveExplorer.Selection()

 

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thank you so much for your help, Mr. Water. However, I'm still unable to make it work. I've written the following code:

#include <OutlookEX.au3>

Global $oOutlook = _OL_Open()
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", _
"Error creating a connection to Outlook. @error = "& @error & ", @extended = " & @extended)
Local $aOL_Item

$aOL_Item = _OL_ItemFind ($oOutlook, "*\Sent Items", $olMail, '[Subject] = "Urgent Workflows 5E24"', "","", "EntryID")
If $aOL_Item[0][0] = 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemFind Example Script", _
"Could not find it'. @error =" & @error)
$aOL_Item.Display

Local $ultimo = $aOL_Item[UBound($aOL_Item) - 1][0]
$ultimo.Display

$oResult = _OL_ItemReply ($oOutlook, $ultimo, Default, True)
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemReply Example Script", _
"Error replying to a mail'. @error = " & @error)

$oResult.Display

 I tried to use the _OL_ItemFind function and then display the email, but it didn't work. Then, I used the $ultimo variable to try to display the latest email using the UBound function, but the email still didn't open. It only opens when I use the _OL_ItemReply function with $ultimo.Display. Could you please show me what I might be missing or doing wrong?

Edited by Abraham
Link to comment
Share on other sites

4 hours ago, Abraham said:
$aOL_Item.Display

This does not work, because _OL_ItemFind returns a two dimensional 0-based array.

To make $ultimo.Display work you have to pass the item object to _OL_Item by using:

Local $oLastItem = _OL_ItemGet($aOL_Item[UBound($aOL_Item) - 1][0], Default, -1) ; Use the EntryID to get the items object 
$oLastItem.Display

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Okay, but when I try to use _OL_ItemGet in this way:

#include <OutlookEX.au3>

Global $oOutlook = _OL_Open()
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", _
"Error creating a connection to Outlook. @error = "& @error & ", @extended = " & @extended)
Local $aOL_Item

$aOL_Item = _OL_ItemFind ($oOutlook, "*\Sent Items", $olMail, '[Subject] = "Residencia"', "","", "EntryID")
If $aOL_Item[0][0] = 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemFind Example Script", _
"Could not find it'. @error =" & @error)

Local $oLastItem = _OL_ItemGet($aOL_Item[UBound($aOL_Item) - 1][0], Default, -1) ; Use the EntryID to get the items object
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemGet Example Script", "Error accessing properties. @error = " & @error)

$oLastItem.Display
If @error <> 0 Then Exit MsgBox(16, "Error", _
"Error opening email. @error = "& @error & ", @extended = " & @extended)

_OL_Close($oOutlook)

 I get @error = 2  from the _OL_ItemGet function. Am I doing something wrong?

Link to comment
Share on other sites

@error = 2 stands for "Item could not be found. EntryID might be wrong."
This errors can be found in OutlookEX.au3 in the header for each function.
I suggest to insert

#include <Array.au3>
_ArrayDisplay($aOL_Item)

to make sure the array holds the expected information.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Solution

Yes! It now works! Thank you so much for your help, Mr. Water, I appreciate it. Here, I'm posting the code. I hope others who may have the same question find it helpful.

Best Regards!

#include <OutlookEX.au3>
#include <Array.au3>


Global $oOutlook = _OL_Open()
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", _
"Error creating a connection to Outlook. @error = "& @error & ", @extended = " & @extended)
Local $aOL_Item

$aOL_Item = _OL_ItemFind ($oOutlook, "*\Sent Items", $olMail, '[Subject] = "Residencia"', "","", "EntryID")
If $aOL_Item[0][0] = 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemFind Example Script", _
"Could not find it'. @error =" & @error)
;_ArrayDisplay($aOL_Item)

Local $oLastItem = _OL_ItemGet($oOutlook, $aOL_Item[UBound($aOL_Item) - 1][0], Default, -1) ; Use the EntryID to get the items object
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemGet Example Script", "Error accessing properties. @error = " & @error)

$oLastItem.Display
If @error <> 0 Then Exit MsgBox(16, "Error", _
"Error opening email. @error = "& @error & ", @extended = " & @extended)

_OL_Close($oOutlook)
Link to comment
Share on other sites

👍

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...