Jump to content

OutlookEX UDF - Help & Support (III)


water
 Share

Recommended Posts

I use Google and look for something like this "Outlook 2016 create mail item signature visual basic".

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

Another idea:
When you check OL_itemCreate.au3, Example 1, you will see that Word can be used as editor too.

The following example works for Outlook 2010:

#include <OutlookEX.au3>

Global $oOutlook = _OL_Open()
$oItem = _OL_ItemCreate($oOutlook, $olMailItem, "", "", "Subject=Subject for BodyFormat=RTF")
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF:", "Error creating the mail item. @error = " & @error & ", @extended = " & @extended)

; Set the body using Word as editor
Global Const $wdCollapseStart = 1 ; Collapse the range to the starting point
Global Const $wdWord = 2 ; A word
Global Const $wdCharacter = 1 ; A character

Global $oDoc = $oItem.GetInspector.WordEditor ; Get the Microsoft Word Document Object Model
Global $oRange = $oDoc.Range ; Get the range object
$oRange.Collapse($wdCollapseStart) ; Move the range start/end to the start of the document
$oRange.Insertbefore("This is a test") ; Insert some text
$oItem.Display()
MsgBox(64, "OutlookEX UDF", "The body of this mail has been created using Microsoft Word as editor.")
$oItem.Close($olSave)

 

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

  • 2 weeks later...
On 18/04/2017 at 5:04 PM, water said:

Another idea:
When you check OL_itemCreate.au3, Example 1, you will see that Word can be used as editor too.

The following example works for Outlook 2010:

#include <OutlookEX.au3>

Global $oOutlook = _OL_Open()
$oItem = _OL_ItemCreate($oOutlook, $olMailItem, "", "", "Subject=Subject for BodyFormat=RTF")
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF:", "Error creating the mail item. @error = " & @error & ", @extended = " & @extended)

; Set the body using Word as editor
Global Const $wdCollapseStart = 1 ; Collapse the range to the starting point
Global Const $wdWord = 2 ; A word
Global Const $wdCharacter = 1 ; A character

Global $oDoc = $oItem.GetInspector.WordEditor ; Get the Microsoft Word Document Object Model
Global $oRange = $oDoc.Range ; Get the range object
$oRange.Collapse($wdCollapseStart) ; Move the range start/end to the start of the document
$oRange.Insertbefore("This is a test") ; Insert some text
$oItem.Display()
MsgBox(64, "OutlookEX UDF", "The body of this mail has been created using Microsoft Word as editor.")
$oItem.Close($olSave)

 

Sorry for the late reply.

 

And thanks for this perfect solution, when using word as editor, it works perfectly in Outlook 2016!

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

17 hours ago, water said:

:) 

Sorry to mention this, after double checking, the code to call wordeditor results the body only contains signature without the message that intended to append. :(

 

Link to comment
Share on other sites

After some testing, I think I found the cause of this issue (still don't know how to fix it):

Here the code I used to test:

#include <OutlookEX.au3>

Global $sOrigBody, $oItem


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

$oItem = _OL_ItemCreate($oOutlook, $olMailItem)
$oItem.BodyFormat = $olFormatHTML
$sOrigBody = $oItem.HTMLBody
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error saving the body to a variable. @error = " & @error & ", @extended = " & @extended)

$oItem.GetInspector
$oItem.HTMLBody = "test" & @CRLF & $sOrigBody
$oItem.Display
_OL_Close($oOutlook)

The error comes out:

Error saving the body to a variable. @error = -2147467260, @extended = 0

I googled the error code, it means operation aborted or transaction aborted. So the question is, what may cause this to abort? Any ideas?

 

 

 
Link to comment
Share on other sites

You could add some additional error checking (plus I added a save statement):

$oItem = _OL_ItemCreate($oOutlook, $olMailItem)
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating item. @error = " & @error & ", @extended = " & @extended)
$oItem.BodyFormat = $olFormatHTML
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error modifying item. @error = " & @error & ", @extended = " & @extended)
$oItem.Save() ; Added because the item has been modified.
$sOrigBody = $oItem.HTMLBody
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error saving the body to a variable. @error = " & @error & ", @extended = " & @extended)

 

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

  • 2 weeks later...

Hi,

I am using your brilliant OutlookEX code to iterate through a directory of MSG files to extract data. (Sender,To,CC,BCC) It works beautifully except if it encounters a msg file which contains a meeting request at which point it errors with an array dimension issue.

I have used _displayarray to see what was contained within the array and it is empty. But when I view the properties of a meeting request MSG file using the excellent MFCMAPI tool, I can see that all of the properties that I need to extract are within the MSG file.

Why can I extract the required properties from a normal "email" msg file, but not a "meeting request" msg file?

 

Any help is greatly appreciated, I can provide some dummy emails showing the issue if that would help.

Many Thanks.

 

 

Link to comment
Share on other sites

Welcome to AutoIt and the forum!

Glad you like my UDF :) 
Can you please provide the error message you get and the line of code you use to extract the data?

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

17 minutes ago, water said:

Welcome to AutoIt and the forum!

Glad you like my UDF :) 
Can you please provide the error message you get and the line of code you use to extract the data?

Thank you for your rapid response, the code I am using is quite long winded but the snippet below reproduces the issue I am having...

#include <outlookex.au3>
Global $oOutlook = _OL_Open()

;TEST1.MSG - "EMAIL" MSG
;TEST2.MSG - "MEETING" MSG

$MsgPath = ('c:\testemails\test1.msg')
$oItem = _OL_Itemcreate($oOutlook, $olMailItem, "", $MsgPath)

$aProperties = _OL_ItemGet($oOutlook, $oItem, Default, "To")
MsgBox(0,"",$aProperties[1][1])
$oItem.Close(1)

Test1.msg works as expected and returns the contents of the "To" field in delimited format.

Test2.msg errors with....

"C:\mamextract\tasktest.au3" (11) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
MsgBox(0,"",$aProperties[1][1])
MsgBox(0,"",^ ERROR

 

I have a couple of email samples but can't post them here as they contain private email address info. I will see if I can replicate it using a msg containing dummy names/addresses. Failing that can I send you a msg that I am having problems with?

Thank you for your assistance.

Link to comment
Share on other sites

You need to check the value of @error after _OL_ItemCreate. If it is <> 0 then there was a problem creating the item.

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

10 minutes ago, water said:

You need to check the value of @error after _OL_ItemCreate. If it is <> 0 then there was a problem creating the item.

Hi Water, just checked and it creates the item without throwing an error. If I change the code to...

#include <outlookex.au3>
Global $oOutlook = _OL_Open()

;TEST1.MSG - "EMAIL" MSG
;TEST2.MSG - "MEETING" MSG

$MsgPath = ('c:\testemails\test1.msg')
$oItem = _OL_Itemcreate($oOutlook, $olMailItem, "", $MsgPath)

;THIS TIME GET ALL OF THE PROPERTIES
$aProperties = _OL_ItemGet($oOutlook, $oItem, Default, "")
_displayarray($aProperties)
$oItem.Close(1)

It works without error, and the contents of the array is.....

Spoiler

Row|Col 0|Col 1|Col 2
[0]|61|3|
[1]|Actions||0
[2]|Application||0
[3]|Attachments||0
[4]|AutoForwarded|False|6
[5]|AutoResolvedWinner|False|6
[6]|BillingInformation||1
[7]|Body||1
[8]|Categories||1
[9]|Class|56|3
[10]|Companies||1
[11]|Conflicts||0
[12]|ConversationID||1
[13]|ConversationIndex||1
[14]|ConversationTopic|SD22 -Site Waste Management Course |1
[15]|CreationTime|20170523170742|5
[16]|DeferredDeliveryTime|45010101000000|0
[17]|DeleteAfterSubmit|False|6
[18]|DownloadState|1|3
[19]|EntryID|00000000C49F328ADE420F4C872A1B4485FADC1007002CE3DA2E18BE814DB369F29AC9AD85BC0000003C3A4100001120DCB7F139654CB0D6D4507CAC8B490000B6124F770000|1
[20]|ExpiryTime|45010101000000|0
[21]|FormDescription||0
[22]|GetInspector||0
[23]|Importance|1|3
[24]|IsConflict|False|6
[25]|IsLatestVersion||6
[26]|ItemProperties||0
[27]|LastModificationTime|20170523170742|5
[28]|Links||0
[29]|MarkForDownload|0|3
[30]|MeetingWorkspaceURL||1
[31]|MessageClass|IPM.Schedule.Meeting.Resp.Pos|1
[32]|Mileage||1
[33]|NoAging|False|6
[34]|OriginatorDeliveryReportRequested|False|6
[35]|OutlookInternalVersion|147181|3
[36]|OutlookVersion|14.0|1
[37]|Parent||0
[38]|PropertyAccessor||0
[39]|ReceivedTime|20170523170742|5
[40]|Recipients||0
[41]|ReminderSet|False|6
[42]|ReminderTime|20090217093000|0
[43]|ReplyRecipients||0
[44]|RetentionExpirationDate|45010101000000|5
[45]|RetentionPolicyName||1
[46]|RTFBody|
[47]|Saved|True|6
[48]|SaveSentMessageFolder||0
[49]|SenderEmailAddress|/O=EXCHANGE/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=MICK.BISHOP|1
[50]|SenderEmailType|EX|1
[51]|SenderName|Mick Bishop|1
[52]|SendUsingAccount||0
[53]|Sensitivity|0|3
[54]|Sent|False|6
[55]|SentOn|20090210150354|5
[56]|Session||0
[57]|Size|2452|3
[58]|Subject|Accepted: Updated: SD22 -Site Waste Management Course |1
[59]|Submitted|False|6
[60]|UnRead|True|6
[61]|UserProperties||0

But I cannot find in the above output the names I am trying to find, as shown in Outlook (attached screenshot)

 

 

outlook.png

Link to comment
Share on other sites

The Outlook object model does not expose all properties of the item. What you are looking for is property 40 - Recipients. It is a collection object as there might be more than a single participant of the meeting.
I can't test at the moment but when you try to retrieve property "Recipients" your script should not crash any longer but return an object. Looping through the members of the recipients collection you should be able to retrieve the Display names of all invited people.
Maybe I can post an example tomorrow.

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

Will check tomorrow when I'm back to my Office.

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

I have figured out a workaround. If I change the message class on the problematic msg file from IPM.Schedule.Meeting.Resp.Pos to IPM.Note. I can then open it using the OutlookEX and I am able to get the data that I want (To/CC/BCC). At the moment I am using MFCMAPI to change the message class. But I note within your UDF there is a function _OL_FolderClassSet ? Can I use that to change the message class within the msg file? If so I presume I would need to open the item, change the class and then save the item and then open it again to read the properties? And then I would need to again change the message class back to IPM.Schedule.Meeting.Resp.Pos . Its certainly a long winded approach but fortunately these meeting class emails only account for a small fraction of the overall number of msg files (4.8Million of them!)

Note I believe the msg files I am dealing with are not exactly normal... basically they are from a large exchange archive which has been archiving emails for over 10 years now. With the help of your UDF the contents are being exported. I believe the archiving system must have some how mangled the original meeting class into a hybrid meeting/note class which has confused OutlookEX/Outlook.

Link to comment
Share on other sites

18 hours ago, de82 said:

Thanks, just tried as suggested but no good :( get Error=4 Extended=-2147352567

Can you please provide the full code you run? _OL_ItemGet does not return @error = 4.

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

Sorry that was me being an idiot and feeding in a file that I had been mucking around with. Using fresh copies of the msg file the result is as follows....

1. If I attempt to retrieve the property "Recipients" It pulls the data but there are no names within the list.

#include <outlookex.au3>
Global $oOutlook = _OL_Open()

;TEST1.MSG - "EMAIL" MSG
;TEST2.MSG - "MEETING" MSG

$MsgPath = ('c:\testemails\test2.msg')
$oItem = _OL_Itemcreate($oOutlook, $olMailItem, "", $MsgPath)
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF:", "Error = " & @error & ", @extended = " & @extended)

$aProperties = _OL_ItemGet($oOutlook, $oItem, Default, "Recipients")
_ArrayDisplay($aProperties)
$oItem.Close(1)

1.png

2. If I attempt to retrieve the property "To" the array is again blank.

#include <outlookex.au3>
Global $oOutlook = _OL_Open()

;TEST1.MSG - "EMAIL" MSG
;TEST2.MSG - "MEETING" MSG

$MsgPath = ('c:\testemails\test2.msg')
$oItem = _OL_Itemcreate($oOutlook, $olMailItem, "", $MsgPath)
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF:", "Error = " & @error & ", @extended = " & @extended)

$aProperties = _OL_ItemGet($oOutlook, $oItem, Default, "To")
_ArrayDisplay($aProperties)
$oItem.Close(1)

2.png

3. If I now change the message class on the affected msg file from  IPM.Schedule.Meeting.Resp.Pos to IPM.Note.  Attempting to extract from the "To" property now works.

3.png

As I said in my previous post I don't believe it is an issue with the UDF or Outlook. The archiving system the MSG files have come from seems to have set a meeting class for the message but the actual properties within the file are for IPM.note class. I pressume Outlook is not exposing the To,CC,Bcc properties as it believes it should be using the "recipents" property which is blank as the actual data lives in the To/CC/Bcc property.

 I am happy to apply the previous workaround I discovered but I am unsure if I can use your UDF to change the msg class?

 

Many thanks once again for your assistance. 

 

 

Edited by de82
Link to comment
Share on other sites

Your first attempt returns the desired result. $aProperties[1][1] is not empty but an object.

MsgBox(0, "", IsObj($aProperties[1][1]))

should return 1 or True.

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

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...