Jump to content

OutlookEX.UDF -- watch inbox of a shared mailbox?


Recommended Posts

Hi,

@water is one of the functions of your OutlookEX.UDF capable to watch the content of the inbox of a shared mailbox, the Outlook / Exchange User has full access to?

Maybe _OL_FolderGet()?

Of coure I've seen your example to get info on the "currently opened folder" in OUTLOOK.EXE:

#include <OutlookEX.au3>

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

; *****************************************************************************
; Example 1
; Get information about the current folder.
; *****************************************************************************
Global $aResult = _OL_FolderGet($oOutlook)
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_FolderGet Example Script", "Error accessing current folder. @error = " & @error & ", @extended = " & @extended)
_ArrayDisplay($aResult, "OutlookEX UDF: properties of the current folder")
_OL_Close($oOutlook)

as well as the function definition in OutlookEX.UDF:

; Syntax.........: _OL_FolderGet($oOL[, $vFolder = ""])
; Parameters ....: $oOL     - Outlook object returned by a preceding call to _OL_Open()
;                  $vFolder - [optional] Folder object as returned by _OL_FolderAccess or full name of folder (default = "" = current folder)

 

What would I need to pass as $vFolder, when the folder in question would be the "Inbox" (German: "Posteingang") of a shared mailbox named "OtherUser" (Email: OtherUser@company.com, SAM=AD\OtherUser). That Mailbox is "bound into" the user's Outlook

 

Or maybe there is a much more simple approach to meet the following request?

I was asked if I can see an option to config a notification for "new mail" coming in to a shared mailbox, as it's automatically showing up for the user's own mailbox. So far I found recommendations to forward all mails from the shared mailbox to that user, then to setup a rule for "Mails forwarded from the shared mailbox", action = Notify & delete (from user's own mailbox' inbox)

 

I also figured out, that it's possible using Exchange Remoteing with get-mailboxfolderstatistics to monitor the number of emails in the shared mailbox "inbox".

Unfortunately that cmdlet is proviced by the Exchange server, the powershell Ex-Remoting session is connecting to -- and most of the commands are provided only, if the currently logged on user has high admin privileges. ("Get-EXCommand | measure"  with Exchange Admin rights is counting almost 1100 commands. When starting an Ex-Remoting PS-Session as "usual user" it's just 300+ commands)

 

Any suggestions appreciated, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to post
Share on other sites

I think the following thread should give you the solution.

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.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
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
Share on other sites

Hello @water

thanks for your reply.

I guess that _OL_FolderAccess() might be the appropriate approach to access folder(s)? 🤔

 

From the OutlookEX wiki:

https://www.autoitscript.com/wiki/OutlookEX_UDF_-_Folder_Item

This is how you would access the shared folder:

Global $aFolder = _OL_FolderAccess($oOutlook, "shared@company.com") Inbox

 

Just starting to try to access the "Inbox" of a shared mailbox (not an exchange shared folder -- maybe that's the fault?) I get this:

 

#include <OutlookEX.au3>

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

;~ Global $Result = _OL_TestEnvironmentCreate($oOutlook)
;~ If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF - Manage Test Environment", "Error creating the test environment. @error = " & @error & ", @extended = " & @extended)
;~ MsgBox(0, '', $Result)

; *****************************************************************************
; Example 1
; Access a folder of the test environment --> ??????????
; *****************************************************************************
$SharedBox="OtherBox@company.de"
Global $aFolder = _OL_FolderAccess($oOutlook, $SharedBox)
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_FolderAccess Example 1", "Error accessing inbox of '" & $SharedBox & "'" & @CRLF & _
"@error = " & @error & @CRLF & _
"@extended = " & @extended)
Global $aFolderDisplay[6][2] = [[$aFolder[0]],["","Folder object"],["","Default item type for the folder"],["", "StoreID where the folder resides"],["", "EntryID of the folder"],["", "Folder path"]]
$aFolderDisplay[1][0] = $aFolder[1]
$aFolderDisplay[2][0] = $aFolder[2]
$aFolderDisplay[3][0] = $aFolder[3]
$aFolderDisplay[4][0] = $aFolder[4]
$aFolderDisplay[5][0] = $aFolder[5]
_ArrayDisplay($aFolderDisplay, "Folder 'inbox' of '" & $SharedBox & "' successfully accessed.")

Result:

  • _OL_Open() correctly returns a result of VARTYPE=Object
    So I belive that the "connection to outlook.exe" was established correctly?
    (Outlook is running alreadey at the time I run the script)
     
  • _OL_FoderAccess($oOutlook,$SharedBox) is returing
    @error = 4
    @extended = 1
    4 - Specified folder could not be found.
    1 - @extended is set to the index of the subfolder in error (1 = root folder)

 

Once I should succeed to access the "other folder's inbox" I thing the _OL_FolderGet() will do the rest of my task:

; #FUNCTION# ====================================================================================================================
; Name...........: _OL_FolderGet
; Description ...: Returns information about the current or any other folder.
; Syntax.........: _OL_FolderGet($oOL[, $vFolder = ""])
; Parameters ....: $oOL     - Outlook object returned by a preceding call to _OL_Open()
;                  $vFolder - [optional] Folder object as returned by _OL_FolderAccess or full name of folder (default = "" = current folder)
; Return values .: Success - one-dimensional one based array with the following information:
;                  |1  - Object to the folder
;                  |2  - Default item type (integer) for the specified folder. Defined by the Outlook OlItemType enumeration
;                  |3  - StoreID (string) of the store to access the folder by ID
;                  |4  - EntryID (string) of the folder to access the folder by ID
;                  |5  - Display name of the folder
;                  |6  - The path of the selected folder
;                  |7  - Number of unread items in the folder <--- this one, and ...
;                  |8  - Total number of items in the folder  <--- that one ... ;-)

 

regards, Rudi.

 

<edit>

maybe I should mention, that this Outlook is localized for GERMAN language. So "inbox" is named "Posteingang" -- is this a constraint?

And anotherone: It's Outlook 64bit, as I need the 64bit "MS ACCESS" components for the AUTODESK CAD products installed. (Inventor and Vault)

 

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to post
Share on other sites

OK, I figured out, that ...

  • 64bit Office doesn't matter
  • "inbox" has to be replaced by "Posteingang" (German localized Office)
  • And I can access my own mailbox, but not a shared one I have full access to.

 

#include <OutlookEX.au3>

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

;~ Global $Result = _OL_TestEnvironmentCreate($oOutlook)
;~ If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF - Manage Test Environment", "Error creating the test environment. @error = " & @error & ", @extended = " & @extended)
;~ MsgBox(0, '', $Result)

; *****************************************************************************
; Example 1
; Access a folder of the test environment --> ??????????
; *****************************************************************************

Enum $iCount,$iObj,$iType,$iStoreID,$iEntryID,$iFPath

$MailboxInbox="ThisIsMe@company.de\Posteingang"

Global $aFolder = _OL_FolderAccess($oOutlook, $MailboxInbox)
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_FolderAccess Example 1", "Error accessing inbox of '" & $MailboxInbox & "'" & @CRLF & _
"@error = " & @error & @CRLF & _
"@extended = " & @extended)
Global $aFolderDisplay[6][2] = [[$aFolder[0]],["","Folder object"],["","Default item type for the folder"],["", "StoreID where the folder resides"],["", "EntryID of the folder"],["", "Folder path"]]
$aFolderDisplay[1][0] = $aFolder[1]
$aFolderDisplay[2][0] = $aFolder[2]
$aFolderDisplay[3][0] = $aFolder[3]
$aFolderDisplay[4][0] = $aFolder[4]
$aFolderDisplay[5][0] = $aFolder[5]
_ArrayDisplay($aFolderDisplay, "Folder 'inbox' of '" & $MailboxInbox & "' successfully accessed.")

$aContentInfo=_OL_FolderGet($oOutlook,$aFolder[$iObj])


_ArrayDisplay($aContentInfo, "7=unread, 8=total")

When I replace the value of $MailboxInbox with "sharedmailbox@company.de\Posteingang" I'm getting @error = 4, @extended = 1

is there something like a "wellknown SID" for default folders like "inbox", that's always the same, no matter what language this office is localized to?

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to post
Share on other sites

Some kind of SID is the $iFolderType. But this does not work for shared folders at the moment. So you have to specify the language specific name of the Inbox.
As I'm working on a german system as well I just tested our GDPR inbox by using:

Global $aFolder = _OL_FolderAccess($oOutlook, "GDPR@company.com\Posteingang")

and it works great.

Make sure you use the correct name of the shared folder. Rightclick the root of the shared folder, select Properties ("Datendateieigenschaften") and make sure the name specified on the general ("Allgemein") tab is the name you use in _OL_FolderAccess.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.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
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
Share on other sites

Hello,

thanks for your reply.

 

Accessing the shared mailbox that way is giving me @error = 4, @exdended = 1

 

I do have full access rights including sendonbehalfof to that other mailbox, and it's "bound into" my outlook 2016 x64 installation.

 

How to track down why the access to that mailbox' inbox = "otherbox@company.com\Posteingang" is not possible?

 

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

$MailboxInbox="OtherBox@company.de\Posteingang"
Global $aFolder = _OL_FolderAccess($oOutlook, $MailboxInbox)

; Results: 
; @error = 4
; @extended = 1

<edit>

Not sure about the apropriate English terms: I'm trying to access the inbox of a shared mailbox, it's a "normal" mailbox several users have access rights to to access it and to SendOnBehalfOf.
This is not an Exchange Shared Folder.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to post
Share on other sites
1 hour ago, rudi said:

This is not an Exchange Shared Folder.

What is it then? The mailbox of another user? Mailbox on another non Exchange system? ...

BTW: Ich habe kein Problem mit nicht englischen Fragestellungen ;)

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.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
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
Share on other sites

Okay, so I'll write it both, English (that's polite in an English forum) and German (that's more easy to me to tell, what I mean)

 

The "other" mailbox was created as a regular Exchange mailbox. It is not a personal maibox of some person, but a mailbox for some project 8 people have access to and the rights to "sendonbehalfof" from that mailbox to external development partners.

 

The users in that internal development team were asking for "There is new mail" notifications also coming from the inbox of that "shared mailbox".

 

Das ist ursprünglich eine ganz normale User Mailbox. Die gehört aber nicht zu einer natürlichen Person, sondern wird intern von einem Entwicklerteam genutzt, um so in Austausch mit einem externen Dienstleister zu treten. Der User zu dieser Mailbox wird von niemandem zur Anmeldung an Windows oder für direkte Nutzung von Exchange 2016 (OL/OWA) genutzt.

Die Mailbox ist bei den internen Entwicklern unten in der Navi Leiste von deren Outlook Email Exchange Konto eingeblendet. So sieht man, welche Emails noch ungelesen sind, im Gegensatz zu Verteilerlisten: Da kriegt jeder eine Kopie und niemand hat eine Ahnung, wer sich um eine gestellte Aufgabe evtl. bereits kümmert.

Die Entwickler hätten jetzt gerne, dass die "Neue Email" Popup Benachrichtigung auch hochkommt, wenn im Posteingang dieser "shared mailbox" neue Email eintrudeln.

 

Geht grundsätzlich mit Powershell EX-Remoting Erweiterungen, aber nicht für gewöhnliche User. Da steht insbes. das Commandlet Get-MailboxFolderStatistics nicht zur Verfügung. Sonst wär's schon erledigt. Also hoffe ich, dass das über OutlookEX funktionieren kann.

Schöne Grüße, Rudi.

Powershell:

# Make sure we are running in the EMS
$RemoteExchange="C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1"
try {$null = get-excommand}
catch [System.Management.Automation.CommandNotFoundException] {
  Write-Warning "Exchange Remoting ist nicht geladen"
	if (test-path $RemoteExchange) {
		. $RemoteExchange
	} else {
		write-warning "Exchange Remoting ist auf diesem PC nicht installiert"
		exit;
	}
}


$MailCount=$(get-mailbox g-cut | get-mailboxfolderstatistics | ?{$_.name -match "posteingang"} | select itemsinfolder).itemsinfolder
$wshell = New-Object -ComObject Wscript.Shell
$Output=$wshell.Popup("$MailCount Emails im Posteingang",1000,"G-Cut Sammelmailbox")

do {
	$NewCount=$(get-mailbox g-cut | get-mailboxfolderstatistics | ?{$_.name -match "posteingang"} | select itemsinfolder).itemsinfolder
	if ($NewCount -eq $MailCount) {
		start-sleep -s 60
	} else {
		$Output=$wshell.Popup("$MailCount Emails im Posteingang",10,"G-Cut Sammelmailbox")
		if ($Output -eq 1) { # Fenster wurde mit OK quittiert
			$MailCount=$NewCount
		}
			
	}
}

until (2 -eq 1)

 

 

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to post
Share on other sites
22 hours ago, water said:

Make sure you use the correct name of the shared folder. Rightclick the root of the shared folder, select Properties ("Datendateieigenschaften") and make sure the name specified on the general ("Allgemein") tab is the name you use in _OL_FolderAccess.

Can you please provide this information (anonymize personal or confidential information e.g. by replacing John.Doe@microsoft.com with Firstname.lastname@company.com)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.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
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
Share on other sites

To access my own mailbox I specify "ThisIsMe@company.de\Posteingang", works like a charme. Email = ThisIsMe@company.de\Posteingang, SAM = AD\ThisIsMe

 

To access the other mailbox  I specify "OtherBox@company.de\Posteingang" 

Returing @error = 4, @Extended = 1

 

Email = OtherBox@company.de

SAM = AD\OtherBox

This is the script to grant the required rights to the "regular users" accessing that "shared mailbox"

# diese Mailboxes sollen zugriff auf das Sammelpostfach erhalten

$U1 = get-mailbox ad\SAM1
$U2=get-mailbox ad\SAM2
$U3=get-mailbox ad\SAM3

# 
$aUsers=@($U1,$U2,$U3)

# auf diese Mailbox sollen die User oben zugriff bekommen
$Sammelpostfach=get-mailbox ad\OtherBox # email = OtherBox@company.de. Inbox = "OtherBox@company.de\Posteingang"

foreach ($User in $aUsers) {
	Add-MailboxPermission -Identity $Sammelpostfach -User $User -AccessRights FullAccess -InheritanceType All -automapping $True
	$Sammelpostfach | Add-ADPermission -user $User -extendedrights "send-as"
	$Sammelpostfach | set-mailbox -grantsendonbehalfto @{add=$user}
}


 

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to post
Share on other sites

To access the Mailbox of another user you have to specify:

$aFolder = _OL_FolderAccess($oOutlook, "\\OtherBox@company.de\Posteingang") 

or

$aFolder = _OL_FolderAccess($oOutlook, "\\OtherBox@company.de", $olFolderInbox)

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.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
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
Share on other sites

Thanks for your reply.

 

$aFolder = _OL_FolderAccess($oOutlook, "\\OtherBox@company.de\Posteingang")

Results:
@@ Debug(19) : VarType $aFolder = String
>Error code: 0
@extended: 0
$aFolder = ''

the other line is asking twice for "Grant Program access to Outlook?", same result inside the script and the debug info below:

$aFolder = _OL_FolderAccess($oOutlook, "\\OtherBox@company.de", $olFolderInbox)

Results:
@@ Debug(19) : VarType $aFolder = String
>Error code: 0
@extended: 0
$aFolder = ''
OK
COM Error Encountered in test.au3
UDF version = 
  OutlookEX_Base: 1.2.3.0 2020-12-10
  OutlookEX: 1.6.3.1 2020-12-15
@AutoItVersion = 3.3.14.5
@AutoItX64 = 0
@Compiled = 0
@OSArch = X64
@OSVersion = WIN_10
Scriptline = 945
NumberHex = 0x80020009
Number = -2147352567
WinDescription = Ausnahmefehler aufgetreten.
Description = Dieser Vorgang konnte wegen eines Registrierungs- oder Installationsproblems nicht ausgeführt werden. Starten Sie Outlook neu, und versuchen Sie es erneut. Falls das Problem weiterhin besteht, installieren Sie Outlook erneut.
Source = Microsoft Outlook
HelpFile = 
HelpContext = 0
LastDllError = 0

Description = This operation could not be performed because of a registration or installation problem. Restart Outlook and try again. If the problem persists, reinstall Outlook.

I don't face any other constraints with outlook, and accessing my *OWN* mailbox is working fine.

restarting outlook.exe doen't change the behavior...

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to post
Share on other sites

I just recognized, that using "\\" as "Mailbox-Prefix" for my own mailbox is a showstopper, too: Is that just required *AND* allowed only for "other mailboxes?

 

#include <OutlookEX.au3>
#include <Debug.au3>

_OL_ErrorNotify(2)
Global $aFolder = _OL_FolderAccess($oOApp, "MyBox@company.de\Posteingang")
; this works. $aFolder[5] = "\\MyBox@Company.de\Posteingang"
; --------

Global $aFolder = _OL_FolderAccess($oOApp, "MyBox@company.de",$olFolderInbox)
; asking twice for "Allow to access Outlook". Then the error TXT block from the previous posting

Global $aFolder = _OL_FolderAccess($oOApp, "\\MyBox@company.de\Posteingang")
; @error = 4, @extended = 1
; --------

Global $aFolder = _OL_FolderAccess($oOApp, "MyBox@company.de","Posteingang")
... and ...
Global $aFolder = _OL_FolderAccess($oOApp, "admin@goepfert.de",$olFolderInbox)
; $aFolder[5] = "\\MyBox@Company.de", so not pointing to the "inbox"
; --------

 

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to post
Share on other sites
On 2/16/2021 at 3:33 PM, water said:

Some kind of SID is the $iFolderType. But this does not work for shared folders at the moment.

As I posted above. That's the reason why examples 4 and 5 do not work.
"\\MyBox@company.de\Posteingang" can be replaced with "\\*\Posteingang".
"MyBox@company.de" is usually "Firstname.Lastname@company.de". is this correct?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.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
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
Share on other sites

Hello @water

thanks for your reply.

the other mailbox has for the AD account *NO* firstname set, just lastname. The Email Address = "g-cut@company.com"

 

Trying several combinations I do not really see, what's going on.

For my own mailbox I'm getting these results:

#AutoIt3Wrapper_Au3Check_Stop_OnWarning=Y
#include <OutlookEX.au3>
#include <Debug.au3>

_OL_ErrorNotify(2)
; *****************************************************************************
; Example Script
; Handle Outlook Folder event when a new item arrives in a folder.
; This script checks the Sent Items folder to display a message when a mail
; has been sent (= a copy of the sent mail is stored in this folder).
; This script loops until Shift-Alt-E is pressed to exit.
; *****************************************************************************

#include <OutlookEX.au3>
#include <Debug.au3>

_OL_ErrorNotify(2)
ConsoleWrite("$olFolderInbox = '" & $olFolderInbox & "'" & @CRLF)

$oOApp=_OL_Open()



; Sample 1:
$Mailbox="MyMailAddress@company.com"
$Param3=$olFolderInbox
; returns object for $aFolder[1], $aFolder[5] = "\\" & $Mailbox
; $aContentInfo[7|8] both are "0"
; $aContentinfo[5]=$Mailbox
; $aContentinfo [6] = "\\" & $Mailbox

; Sample 2:
$Mailbox="MyMailAddress@company.com\Posteingang"
$Param3=""
; returns object for $aFolder[1], $aFolder[5] = "\\" & $Mailbox & "\Posteingang",
; $aContentInfo[7|8] correctly present "unread" and "total" count
; $aContentinfo[5]=$Mailbox
; $aContentinfo [6] = "\\" & $Mailbox & "\Posteingang"

; Sample 3:
$Mailbox = "Rudi Thilo"
$param3=""
; OutlookEX Base UDF debug info

; Sample 4:
$Mailbox = "\\Rudi Thilo"
$param3=""
; @@ Debug(65) : VarType $aFolder = String
; >Error code: 0
; @extended: 0
; $aFolder = ''

; Sample 5:
$Mailbox = "\\Rudi Thilo\Posteingang"
$param3=""
; same as sample 4

; Sample 6:
$Mailbox = "\\Rudi Thilo" ; this is firstname lastname
$param3=$olFolderInbox
; same as sample 1


Global $aFolder = _OL_FolderAccess($oOApp, $Mailbox,$Param3)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : VarType $aFolder = ' & VarGetType($aFolder) & @CRLF & '>Error code: ' & @error & @CRLF & "@extended: " & @extended & @CRLF) ;### Debug Console
if IsArray($aFolder) then
    _DebugArrayDisplay($aFolder)
    Enum $iCount,$iObj,$iType,$iStoreID,$iEntryID,$iFPath
    $aContentInfo=_OL_FolderGet($oOApp,$aFolder[$iObj])
    _ArrayDisplay($aContentInfo, "7=unread, 8=total")
Else
    ConsoleWrite("$aFolder = '" & $aFolder& "'" & @CRLF & "---------------" & @CRLF)
EndIf

for the other mailbox it looks like this.

The user belonging to that mailbox has no firstname defined. Lastname = Email prefix before the "@" in the mail address.

#AutoIt3Wrapper_Au3Check_Stop_OnWarning=Y
#include <OutlookEX.au3>
#include <Debug.au3>

_OL_ErrorNotify(2)
; *****************************************************************************
; Example Script
; Handle Outlook Folder event when a new item arrives in a folder.
; This script checks the Sent Items folder to display a message when a mail
; has been sent (= a copy of the sent mail is stored in this folder).
; This script loops until Shift-Alt-E is pressed to exit.
; *****************************************************************************

#include <OutlookEX.au3>
#include <Debug.au3>

_OL_ErrorNotify(2)
ConsoleWrite("$olFolderInbox = '" & $olFolderInbox & "'" & @CRLF)

$oOApp=_OL_Open()



; Sample 1:
$Mailbox="g-cut@company.com"
$Param3=$olFolderInbox
; OutlookEX Base UDF debug info

; Sample 2:
$Mailbox="g-cut@company.com\Posteingang"
$Param3=""
; same as sample 1, OutlookEX Base UDF debug info

; Sample 3:
$Mailbox = "g-cut"
$param3=""
; OutlookEX Base UDF debug info

; Sample 4:
$Mailbox = "\\g-cut"
$param3=""
; @@ Debug(61) : VarType $aFolder = String
; >Error code: 0
; @extended: 0
; $aFolder = ''

; Sample 5:
$Mailbox = "\\g-cut\Posteingang"
$param3=""
; same as sample 4

; Sample 6:
$Mailbox = "\\g-cut" ; this is firstname lastname
$param3=$olFolderInbox
; same as sample 1, OutlookEX Base UDF debug info

; Sample 7:
$Mailbox="\\g-cut@company.com\Posteingang"
$Param3=""
; @@ Debug(61) : VarType $aFolder = String
; >Error code: 0
; @extended: 0
; $aFolder = ''

$Mailbox="\\g-cut@company.com"
$Param3=$olFolderInbox
; same as sample 1, OutlookEX Base UDF debug info




Global $aFolder = _OL_FolderAccess($oOApp, $Mailbox,$Param3)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : VarType $aFolder = ' & VarGetType($aFolder) & @CRLF & '>Error code: ' & @error & @CRLF & "@extended: " & @extended & @CRLF) ;### Debug Console
if IsArray($aFolder) then
    _DebugArrayDisplay($aFolder)
    Enum $iCount,$iObj,$iType,$iStoreID,$iEntryID,$iFPath
    $aContentInfo=_OL_FolderGet($oOApp,$aFolder[$iObj])
    _ArrayDisplay($aContentInfo, "7=unread, 8=total")
Else
    ConsoleWrite("$aFolder = '" & $aFolder& "'" & @CRLF & "---------------" & @CRLF)
EndIf

 

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to post
Share on other sites

Working example for a shared mailbox. We need to check which kind of mailbox we are talking about for g-cut:

#include <OutlookEX.au3>
#include <MsgBoxConstants.au3>

; *****************************************************************************
; Example Script
; Handle Outlook ItemAdd event when a new mail item arrives in your Inbox.
; This example works for an Inbox of another user or a shared mailbox.
; This script loops until Shift-Alt-E is pressed to exit.
; *****************************************************************************
HotKeySet("+!e", "_Exit") ; Shift-Alt-E to Exit the script
Global $sMailbox = "mailbox@company.com\Inbox" ; <== replace with the mailbox you want to monitor
Global $sTitle = "OutlookEX UDF Example Script"
MsgBox($MB_IconInformation, $sTitle, "Hotkey to exit the script: 'Shift-Alt-E'!", 10) ; Wait 10 seconds, then continue

; Start or connect to a running Outlook instance
Global $oOL = _OL_Open()
If @error Then Exit MsgBox($MB_IconError, $sTitle, "Error when calling _OL_Open: @error=" & @error & ", @extended=" & @extended & @CRLF)

; Access the Mailbox
Global $aFolder = _OL_FolderAccess($oOL, $sMailbox)
If @error Then Exit MsgBox($MB_IconError, $sTitle, "Error when calling _OL_FolderAccess: @error=" & @error & ", @extended=" & @extended & @CRLF)

; Create a collection of the items in this mailbox
Global $oItems = $aFolder[1].Items
If @error Then Exit MsgBox($MB_IconError, $sTitle, "Error when accessing the folder items: @error=" & @error & ", @extended=" & @extended & @CRLF)

; Create the events for this collection. Outlook calls a function starting with "oOL_" for each event. For the ItemAdd event function oOL_ItemAdd will be called
Global $oTemp = ObjEvent($oItems, "oOL_")
If @error Then Exit MsgBox($MB_IconError, $sTitle, "Error when calling ObjEvent: @error=" & @error & ", @extended=" & @extended & @CRLF)
ConsoleWrite("OutlookEX UDF Example Script - waiting for new items to arrive!" & @CRLF)

While 1
    Sleep(10)
WEnd

; ItemAdd event - https://docs.microsoft.com/en-us/office/vba/api/outlook.items.itemadd
Func oOL_ItemAdd($oItem)
    ConsoleWrite("OutlookEX UDF Example Script - new item has arrived!" & @CRLF)
    ConsoleWrite( _
            "From:    " & $oItem.SenderName & @CRLF & _
            "Subject: " & $oItem.Subject & @CRLF & _
            "Class:   " & $oItem.Class & " (43=Mail, 53=MeetingRequest ...)" & @CRLF)
EndFunc   ;==>oOL_ItemAdd

Func _Exit()
    _OL_Close($oOL)
    Exit
EndFunc   ;==>_Exit

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.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
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
Share on other sites

hello @water

thanks for the code.

I adusted the variable content for $sMailbox:

 

Global $sMailbox = "g-cut@company.com\Posteingang"

Result:

OK
Error when calling _OL_FolderAccess: @error=4, @extended=1

As I tried to explain above, this is "normal" user mailbox, a couple of different users have full access rights to.

[PS] C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Exchange Server 2016>get-mailbox g-cut | fl *type*


ResourceType         :
RemoteRecipientType  : None
RecipientType        : UserMailbox
RecipientTypeDetails : SharedMailbox

 

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to post
Share on other sites

When you manually create a new mail item and enter "g-cut" as recipient, does Outlook resolve this?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.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
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
Share on other sites

Yes, outook is "expanding" to the full recipient, when entering "g-cut" in the "To..." edit field.

 

But maybe that's due to the fact, that that mailbox is already in the list of "mail-addresses-used-before" (Outlook Address Cache, that can be viewed and edited using Nirsoft's NK2Edit).

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...