Jump to content

Outlook UDF


Wooltown
 Share

Recommended Posts

There is one small problem, if you have a mixed environment with both english and non english clients, then you can't refer to "inbox", in Sweden it's called "inkorgen", then you have to use the method as I have used.

Link to comment
Share on other sites

  • 2 months later...

I have modified the code to accommodate a Microsoft Office Outlook Pop-up with the text 'A program is trying to access e-mail addresses you have stored in Outlook. etc

Opt("TrayIconHide", 1)          ;0=show, 1=hide tray icon
Opt("WinSearchChildren", 1)     ;0=no, 1=search children also

_OutlookWarning()

Func _OutlookWarning()
    For $iNum = 1 to 5
        If WinExists("Microsoft Office Outlook") Then
            While 1
                WinActivate("Microsoft Office Outlook")
                If ControlCommand ("Microsoft Office Outlook","","Button4","IsEnabled") Then
                    Sleep(500)
                    ControlFocus ("Microsoft Office Outlook","","[CLASS:Button; INSTANCE:3]")
                    Send ("{SPACE}")
                    Sleep (500)
                    ControlFocus ("Microsoft Office Outlook","","[CLASS:Button; INSTANCE:4]")
                    Send ("{SPACE}")
                    ExitLoop 2
                EndIf
                Sleep (250)
            Wend
        EndIf
        Sleep(1000)
    Next
EndFunc

Which is producing a Line -1 Error: Variable sued without being declared". It is not obvious as to what variable it is referring to. Can you help Ant..

Link to comment
Share on other sites

Hi Wooltown

I have taken the opportunity to modify your OutlookWarning1.au3 code chancing the For-Next with a While 1-WEnd statement to eliminate a timing issue as to when the Outlook Popup actually appeared and processed by WarningClock [OutlookWarning1.au3 compiled]. This allows me to call the WarningClick program and have it running and waiting just before executing the Outlook Object [send an email]. In addition I am also checking the sizing of the Outlook Window increasing its Height Width values by 50% to provide a 'splashtexton' message mask to cover the Outlook Popup. This is to give the user information that they are not required to respond to the Outlook Security Prompt. You will also note that I have taken out the Sleep(500) statements as they did not appear to be necessary and had the effect of slowing down the process [for no appearent reason]. Look forward to your comments as to the efficacy of the code as modified. There have been no changes to your Func _OutlookSendMail($oOutlook, $sTo, $sCc, $sBcc, $sSubject, $sBody, $sAttachments,$iBodyFormat, $iImportance, $sWarningClick) Script. Everything works perfectly.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=c:\sms_server\warningclick.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

Opt("TrayIconHide", 1)          ;0=show, 1=hide tray icon
Opt("WinSearchChildren", 1)     ;0=no, 1=search children also
;===============================================================================
; ORIGIONAL CODE BY:
; Function Name:    _OutlookWarning()
; Description:      Automatically click on the Yes button when trying to send an email via MS Outlook
 ;Parameter(s):     None
; Requirement(s):   None
; Return Value(s):  None
; Author(s):        Wooltown
; Created:          2009-02-09
; Modified:         2009-02-27
;
;===============================================================================

Global $Title = "sEmailSMS", $Font = "sans-serif", $FontSize = 10, $FontWeight = 600, $Just = 32, $MsgDuration = 40, $SysMessage

_OutlookWarning()
Exit

Func _OutlookWarning()
    While 1
        If WinExists("Microsoft Office Outlook","A program is trying to automatically send e-mail") Then
            $WinSize = WinGetClientSize("Microsoft Office Outlook")
            ;//Message is Designed to mask the Outlook Office Security Prompt
            $SysMessage = "sEmailSMS will Process the" & @CRLF & "'Microsoft Office Outlook' Security Pop-Up" & @CRLF & @LF & "Please wait..."
            _MessageDisplay($MsgDuration, $WinSize[0] * 1.50, $WinSize[1] * 1.50, $Just, $SysMessage)
            While 1
                WinActivate("Microsoft Office Outlook")
                If ControlCommand ("Microsoft Office Outlook","A program is trying to automatically send e-mail","Button4","IsEnabled") Then
                    ControlFocus ("Microsoft Office Outlook","A program is trying to automatically send e-mail","[CLASS:Button; INSTANCE:4]")
                    Send ("{SPACE}")
                    ExitLoop (2)
                EndIf
            Wend
        EndIf
        Sleep(1000)
    WEnd
EndFunc

;//Message Display
Func _MessageDisplay($Duration, $Width, $Height, $Just, $Message)
    Sleep(2000) ;Time Delay between Multiple Messages
    SplashTextOn($Title, $Message, $Width, $Height, -1, -1, $Just, $Font, $FontSize, $FontWeight)
    ;//Length of display in milliseconds
    Sleep($Duration * 100)
    SplashOff()
EndFunc   ;==>_MessageDisplay
Link to comment
Share on other sites

Hi Wooltown

I have taken the opportunity to modify your OutlookWarning1.au3 code chancing the For-Next with a While 1-WEnd statement to eliminate a timing issue as to when the Outlook Popup actually appeared and processed by WarningClock [OutlookWarning1.au3 compiled]. This allows me to call the WarningClick program and have it running and waiting just before executing the Outlook Object [send an email]. In addition I am also checking the sizing of the Outlook Window increasing its Height Width values by 50% to provide a 'splashtexton' message mask to cover the Outlook Popup. This is to give the user information that they are not required to respond to the Outlook Security Prompt. You will also note that I have taken out the Sleep(500) statements as they did not appear to be necessary and had the effect of slowing down the process [for no appearent reason]. Look forward to your comments as to the efficacy of the code as modified. There have been no changes to your Func _OutlookSendMail($oOutlook, $sTo, $sCc, $sBcc, $sSubject, $sBody, $sAttachments,$iBodyFormat, $iImportance, $sWarningClick) Script. Everything works perfectly.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=c:\sms_server\warningclick.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

Opt("TrayIconHide", 1)          ;0=show, 1=hide tray icon
Opt("WinSearchChildren", 1)     ;0=no, 1=search children also
;===============================================================================
; ORIGIONAL CODE BY:
; Function Name:    _OutlookWarning()
; Description:      Automatically click on the Yes button when trying to send an email via MS Outlook
 ;Parameter(s):     None
; Requirement(s):   None
; Return Value(s):  None
; Author(s):        Wooltown
; Created:          2009-02-09
; Modified:         2009-02-27
;
;===============================================================================

Global $Title = "sEmailSMS", $Font = "sans-serif", $FontSize = 10, $FontWeight = 600, $Just = 32, $MsgDuration = 40, $SysMessage

_OutlookWarning()
Exit

Func _OutlookWarning()
    While 1
        If WinExists("Microsoft Office Outlook","A program is trying to automatically send e-mail") Then
            $WinSize = WinGetClientSize("Microsoft Office Outlook")
            ;//Message is Designed to mask the Outlook Office Security Prompt
            $SysMessage = "sEmailSMS will Process the" & @CRLF & "'Microsoft Office Outlook' Security Pop-Up" & @CRLF & @LF & "Please wait..."
            _MessageDisplay($MsgDuration, $WinSize[0] * 1.50, $WinSize[1] * 1.50, $Just, $SysMessage)
            While 1
                WinActivate("Microsoft Office Outlook")
                If ControlCommand ("Microsoft Office Outlook","A program is trying to automatically send e-mail","Button4","IsEnabled") Then
                    ControlFocus ("Microsoft Office Outlook","A program is trying to automatically send e-mail","[CLASS:Button; INSTANCE:4]")
                    Send ("{SPACE}")
                    ExitLoop (2)
                EndIf
            Wend
        EndIf
        Sleep(1000)
    WEnd
EndFunc

;//Message Display
Func _MessageDisplay($Duration, $Width, $Height, $Just, $Message)
    Sleep(2000) ;Time Delay between Multiple Messages
    SplashTextOn($Title, $Message, $Width, $Height, -1, -1, $Just, $Font, $FontSize, $FontWeight)
    ;//Length of display in milliseconds
    Sleep($Duration * 100)
    SplashOff()
EndFunc   ;==>_MessageDisplay

This is a further modification to the Wooltown code which also accommodates a different 'Microsoft Office Outlook' security message which displays if you are using the 'CD0.Message' code published elsewhere in this forum. You will also note that I have changed the code to produce a message mask the exact same size and location of the 'Microsoft Office Outlook' window.

Opt("TrayIconHide", 1)          ;0=show, 1=hide tray icon
Opt("WinSearchChildren", 1)     ;0=no, 1=search children also

;//Global Variables
Global $Title = "sEmailSMS", $Font = "sans-serif", $FontSize = 10, $FontWeight = 600, $Just = 32, $MsgDuration = 40, $SysMessage

;//Call the Warning Click Routine
_OutlookWarning()

;//Exit the Application
Exit

;//Outlook Security Window Processor
Func _OutlookWarning()
    While 1
        ;Send an email using Microsoft Outlook
        If WinExists("Microsoft Office Outlook","A program is trying to automatically send e-mail") Then
            ;//Microsoft Office Outlook Window [x, y, width, height]
            $WinSize = WinGetPos("Microsoft Office Outlook")
            ;//Message is Designed to Mask the Outlook Office Security Prompt
            $SysMessage = "sEmailSMS will process the" & @CRLF & "'Microsoft Office Outlook' Security Pop-Up" & @CRLF & @LF & "Please wait..."
            _MessageDisplay($MsgDuration, $WinSize[2], $WinSize[3], $WinSize[0], $WinSize[1], $Just, $SysMessage)
            While 1
                WinActivate("Microsoft Office Outlook")
                If ControlCommand ("Microsoft Office Outlook","A program is trying to automatically send e-mail","Button4","IsEnabled") Then
                    ControlFocus ("Microsoft Office Outlook","A program is trying to automatically send e-mail","[CLASS:Button; INSTANCE:4]")
                    Send ("{SPACE}")
                    ExitLoop (2)
                EndIf
            Wend
        EndIf
        ;Send an email using CDO.Message [Access allowed for 1 Minute]
        If WinExists("Microsoft Office Outlook","A program is trying to access e-mail addresses you have stored in Outlook") Then
            While 1
                WinActivate("Microsoft Office Outlook")
                $WinSize = WinGetClientSize("Microsoft Office Outlook")
                $SysMessage = "sEmailSMS will process the" & @CRLF & "'Microsoft Office Outlook' Security Pop-Up" & @CRLF & @LF & "Please wait..."
                _MessageDisplay($MsgDuration, $WinSize[2], $WinSize[3], $WinSize[0], $WinSize[1], $Just, $SysMessage)
                If ControlCommand ("Microsoft Office Outlook","A program is trying to access e-mail addresses you have stored in Outlook","Button4","IsEnabled") Then
                    ControlFocus ("Microsoft Office Outlook","A program is trying to access e-mail addresses you have stored in Outlook","[CLASS:Button; INSTANCE:3]")
                    Send ("{SPACE}")
                    Sleep (500)
                    ControlFocus ("Microsoft Office Outlook","A program is trying to access e-mail addresses you have stored in Outlook","[CLASS:Button; INSTANCE:4]")
                    ExitLoop 2
                EndIf
            Wend
        EndIf
        Sleep(1000)
    WEnd
EndFunc

;//Message Display
Func _MessageDisplay($Duration, $Width, $Height, $WinX, $WinY, $Just, $Message)
    SplashTextOn($Title, $Message, $Width, $Height, $WinX, $WinY, $Just, $Font, $FontSize, $FontWeight)
    ;//Length of display in milliseconds
    Sleep($Duration * 100)
    SplashOff()
EndFunc   ;==>_MessageDisplay

;//The WarningClick routine is compiled and called from the Email Processing Program the calling code looks as follows. You will notice that the Warninclick program is executed and active immediately prior to it being needed and closed after it has done its job thereby eliminating the need to have an active timer within the code itself.

#Include <Date.au3>
#Include <Array.au3>

Const $olFormatUnspecified=0
Const $olImportanceNormal=1
Const $olMailItem=0

Global $oOutlook, $sTo, $sCc, $sBcc, $sSubject, $sBody, $sAttachments, $iBodyFormat, $iImportance, $sWarningClick
Global $WarningClick = @ScriptDir & "\WarningClick.exe"

Run($WarningClick)
$oOutlook = _OutlookOpen()
_OutlookSendMail($oOutlook, "anyone@anywhere.net" , "", "", "test", "body of the message test", "",$iBodyFormat = $olFormatUnspecified, $iImportance = $olImportanceNormal, "")
$PID = ProcessExists("WarningClick.exe")
If $PID Then ProcessClose($PID)

Func _OutlookOpen()
    Local $oOutlook = ObjCreate("Outlook.Application")
    If @error Or Not IsObj($oOutlook) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $oOutlook
EndFunc


Func _OutlookSendMail($oOutlook, $sTo, $sCc, $sBcc, $sSubject, $sBody, $sAttachments,$iBodyFormat, $iImportance, $sWarningClick)
    Local $iRc = 0, $asAttachments
    If $sTo = "" And $sCc = "" And $sBCc = "" Then
        Return SetError(1, 0, 0)
    EndIf
    Local $oOuError = ObjEvent("AutoIt.Error", "_OutlookError")
    Local $oMessage = $oOutlook.CreateItem($olMailItem)
    With $oMessage
        .To = $sTo
        .Cc = $sCc
        .Bcc = $sBCc
        .Subject = $sSubject
        .Body = $sBody
        .BodyFormat = $iBodyFormat
       .Importance = $iImportance
        If $sAttachments <> "" Then
            $asAttachments = StringSplit($sAttachments,";")
            For $iNumOfAttachments = 1 to $asAttachments[0]
                .Attachments.Add($asAttachments[$iNumOfAttachments])
            Next
        EndIf
        .Send
        $iRc = @ERROR
    EndWith
    If $iRc = 0 Then
        Return 1
    Else
        Return SetError(9, 0, 0)
    EndIf
    $oOutlook = 0
EndFunc

I claim no credit for the modifications to suit my purpose Wooltown alone is entitled to full credit for the origional code. Well done Wooltown

Edit:

I have had an opportunity to re-work the origional OutlookWarning routine together with my previous renditions [which for my purpose I have called 'OutlookAgent' and through a refining process have setted on the following code:

In practice you call this routine before creating the 'Object' [be it either Local $oOutlook = ObjCreate("CDO.Message") or Local $oOutlook = ObjCreate("Outlook.Application")] and then perform a 'ProcessClose' when processing has completed and you no longer require the Agent to be running.

Opt("TrayIconHide", 1)          ;//Hide Tray Icon
Opt("WinSearchChildren", 1)     ;Search Children [Windows]

#include <Date.au3>     ;//Date Time Processing

;//Global Variables
Global $Title = "sEmailSMS", $Font = "sans-serif", $FontSize = 10, $FontWeight = 600, $Just = 32, $MsgDuration = 4000, $SysMessage, $sExitTimer = 60000

;//Call the Security Routine
_OutlookAgent()

;//Outlook Security Window Processor
Func _OutlookAgent()
    ;//Start the Exit Timer
    Local $ExitTimer = _TimeToTicks(@HOUR, @MIN, @SEC) + $sExitTimer
    While 1
        ;//Default System Message [Mask]
        $SysMessage = "The User Security Agent will RESPOND TO the" & @CRLF & "'Microsoft Office Outlook' Pop-Up" & @CRLF & @LF & "Please wait..."
        ;//Exit when Time Limit Expires
        If _TimeToTicks(@HOUR, @MIN, @SEC) >= $ExitTimer Then ExitLoop
        ;//Check for Window
        If WinExists("Microsoft Office Outlook", "A program is trying to automatically send e-mail") Then
            ;//Microsoft Office Outlook Window [x, y, width, height]
            $WinSize = WinGetPos("Microsoft Office Outlook", "A program is trying to automatically send e-mail")
            SplashTextOn($Title, $SysMessage, $WinSize[2], $WinSize[3], $WinSize[0], $WinSize[1], $Just, $Font, $FontSize, $FontWeight)
            WinActivate("Microsoft Office Outlook")
            While 1
                If ControlCommand ("Microsoft Office Outlook","A program is trying to automatically send e-mail","Button4","IsEnabled") Then
                    ControlFocus ("Microsoft Office Outlook","","[CLASS:Button; INSTANCE:4]")
                    Send ("{SPACE}")
                    Sleep (500)
                    ;//Message Timer
                    Sleep ($MsgDuration)
                    ;//Switch Message Off
                    SplashOff()
                    ExitLoop
                EndIf
            WEnd
            ;//Reset Exit Timer [Allow OutlookAgent to stay active until all Pop-Ups are Processed]
            $ExitTimer = _TimeToTicks(@HOUR, @MIN, @SEC) + $sExitTimer
        EndIf
        ;//Check for Window
        If WinExists("Microsoft Office Outlook", "A program is trying to access e-mail addresses you have stored in Outlook") Then
            $WinSize = WinGetPos("Microsoft Office Outlook", "A program is trying to access e-mail addresses you have stored in Outlook")
            SplashTextOn($Title, $SysMessage, $WinSize[2], $WinSize[3], $WinSize[0], $WinSize[1], $Just, $Font, $FontSize, $FontWeight)
            WinActivate("Microsoft Office Outlook")
            While 1
                If ControlCommand ("Microsoft Office Outlook","A program is trying to access e-mail addresses you have stored in Outlook","Button4","IsEnabled") Then
                    ControlFocus ("Microsoft Office Outlook","","[CLASS:Button; INSTANCE:3]")
                    Send ("{SPACE}")
                    Sleep (500)
                    ControlFocus ("Microsoft Office Outlook","","[CLASS:Button; INSTANCE:4]")
                    Send ("{SPACE}")
                    ;//Message Timer
                    Sleep ($MsgDuration)
                    ;//Switch Message Off
                    SplashOff()
                    ExitLoop
                EndIf
            WEnd
            ;//Reset Exit Timer
            $ExitTimer = _TimeToTicks(@HOUR, @MIN, @SEC) + $sExitTimer
        EndIf
        Sleep(1000)
    WEnd
    ;//Exit when Time Limit Expires  [Note: If running a 'ProcessClose' is Executed by the Calling Program]
    Exit
EndFunc
Edited by anixon
Link to comment
Share on other sites

  • 3 weeks later...

Thanks for sharing! NICE WORK !!! :)

I got an error, can anyone help me with the problem:

When I call _OutlookModifyAppointment() for the second time a got this error:

"Outlook.au3 (1534) : ==> Nested "With" statements are not allowed.:"

code:

$oOutlook = _OutlookOpen()

$xx = _OutlookModifyAppointment($oOutlook, "Test", "2009-10-08 15.00", "Test?", "","", "", "False", "" ,"", "","AA",2)

;

$xx = _OutlookModifyAppointment($oOutlook, "Test", "2009-10-08 17.00", "Test!!", "","", "", "False", "" ,"", "","BB",2)

Link to comment
Share on other sites

Great UDF! Very nice work...

Having a problem getting delete mail working, constantly getting illegal parameter returned.

Would you be able to tell me what I'm doing wrong?

$MailArray = _OutlookGetMail($oOutlook,$olFolderInbox & "\TTDispatch",False,"","","","","","",True,"",0,False)
If @error > 0 Then MsgBox(4096,"Get Mail Error",@error,600)
_ArrayDisplay($MailArray)
;One unread email returned correctly, no issue...

For $mailitem = 1 to (Ubound($MailArray)-1)
    $fromemail = $MailArray[$mailitem][1]
    $subject = $MailArray[$mailitem][7]
    $receivedtime = $MailArray[$mailitem][5]
    ConsoleWrite("Fromname = " & $fromemail & " Subject = " & $subject & " Received Time = " & $receivedtime & @CRLF)
    
        ;example of email parameters
        ;Fromname = /O=EMC/OU=NORTH AMERICA/CN=RECIPIENTS/CN=KASCHP 
        ;Subject = INTRANSIT Re: EMC TriageTrac Dispatch: Barclays Capital SR# 31720334
        ;Received Time = 20091010013225

        $DeleteMessage = _OutlookDeleteMail($oOutlook,$olFolderInbox & "\TTDispatch",$fromemail,$subject,$receivedtime,False,False,"")
    If @error > 0 Then MsgBox(4096,"Delete Message Error",@error,600)
Next

I'm consistently getting illegal parameters regardless of what parameters are omitted. Do the (from email,subject or received) parameters require a different format than what is returned by get mail?

Also, are you aware of any issues with intermittent missing of messages using get mail with the unread only option set to true? It seems to be missing some emails intermittently, it does still mark the messages read but doesn't return them in the array. This is why I'd prefer to delete each message processed rather than just marking it read.

Thanks in advance for any advice you can offer.

Tim

Edited by timevex
Link to comment
Share on other sites

  • 1 month later...

I am looking to generating the "complete directory path" of a folder in Outlook using this function that I am trying to write:

Func GetCompletePath( $folder )

    If IsObj( $folder ) Then
        
        If IsObj( $folder.Parent ) Then
            
            MsgBox( 0, "GetCompletePath", $folder.Parent.Name )
            ; The parent of the Folder object is the Folders collection object.
            Return ( GetCompletePath( $folder.Parent ) & "\" & $folder.Name );
        Else    
            Return $folder.Name;
        EndIf
    Else    
        Return "NA";
    EndIf
EndFunc

The funny thing is that the MsgBox displays the folder name correctly, but then AutoIt terminates saying:

The requested action with this object has failed.:
MsgBox( 0, "GetCompletePath", $folder.Parent.Name )
MsgBox( 0, "GetCompletePath", $folder.Parent.Name ^ ERROR

Any help?

The expected output is "Something\FirstFolder\ThisFolder" if I am in "ThisFolder" under "FirstFolder"

Any alternate way I can get this done?

Edited by JavaAutomater
Link to comment
Share on other sites

I am trying to filter appointments by LastModificationTime

I have modified the _OutlookGetAppointments function adding an additional parameter: $LastModificationTime and adding

script steps that add $LastModificationTime into $sFilter (see code).

I have also added LastModificationTime to the return results.

Last modification time returns in this format: 20091125101920, however I have tried filtering appointments by this and other date / time formats and I do not even get the popup dialog from Outlook that a program is trying to access Outlook. So I assume that I am causing some error.

What am I doing wrong?

Thanks

Func _OutlookGetAppointments($oOutlook, $sSubject = "", $sStartDate = "", $sEndDate = "", $sLocation = "", $iAllDayEvent = 2, $iImportance = "", $LastModificationTime="")
    Local $avAppointments[1000][10], $sFilter = "", $fAllDayEvent, $oFilteredItems
    Local $oOuError = ObjEvent("AutoIt.Error", "_OutlookError")
    Switch $iAllDayEvent
        Case 0
            $fAllDayEvent = False
        Case 1
            $fAllDayEvent = True
    EndSwitch
    $avAppointments[0][0] = 0
    Local $oNamespace = $oOutlook.GetNamespace("MAPI")
    Local $oFolder = $oNamespace.GetDefaultFolder($olFolderCalendar)
    Local $oColItems = $oFolder.Items
    $oColItems.Sort("[Start]")
    $oColItems.IncludeRecurrences = True
    If $sSubject <> "" Then
        $sFilter = '[Subject] = "' & $sSubject & '"'
    EndIf
    If $sStartDate <> "" Then
        If Not _DateIsValid($sStartDate) Then Return SetError(1, 0, 0)
        If $sFilter <> "" Then $sFilter &= ' And '
        $sFilter &= '[Start] >= "' & $sStartDate & '"'
    EndIf
    If $sEndDate <> "" Then
        If Not _DateIsValid($sEndDate) Then Return SetError(1, 0, 0)
        If $sFilter <> "" Then $sFilter &= ' And '
        $sFilter &= '[End] <= "' & $sEndDate & '"'
    EndIf
    If $sLocation <> "" Then
        If $sFilter <> "" Then $sFilter &= ' And '
        $sFilter &= '[Location] = "' & $sLocation & '"'
    EndIf
    If $iImportance <> "" Then
        If $sFilter <> "" Then $sFilter &= ' And '
        $sFilter &= '[Importance] = "' & $iImportance & '"'
    EndIf
    If $LastModificationTime <> "" Then
        If $sFilter <> "" Then $sFilter &= ' And '
        $sFilter &=  '[LastModificationTime] >  "' & $LastModificationTime  & '"'
    EndIf
    $oFilteredItems = $oColItems.Restrict($sFilter)
    ;MsgBox (0,'Filter',$sFilter)
    If $sFilter = "" Then Return SetError(1, 0, 0)
    For $oItem In $oFilteredItems
        $oItem.IsRecurring
            If $avAppointments[0][0] = 999 Then
                SetError (3)
                Return $avAppointments
            EndIf
            If $iAllDayEvent <> 2 Then
                If $fAllDayEvent = True Then
                    If $oItem.AllDayEvent = False Then ContinueLoop
                Else
                    If $oItem.AllDayEvent = True Then ContinueLoop
                EndIf
            EndIf
            $avAppointments[0][0] += 1
            $avAppointments[$avAppointments[0][0]][0] = $oItem.Subject
            $avAppointments[$avAppointments[0][0]][1] = $oItem.Start
            $avAppointments[$avAppointments[0][0]][2] = $oItem.End
            $avAppointments[$avAppointments[0][0]][3] = $oItem.Location
            $avAppointments[$avAppointments[0][0]][4] = $oItem.AllDayEvent
            $avAppointments[$avAppointments[0][0]][5] = $oItem.Importance
            $avAppointments[$avAppointments[0][0]][6] = $oItem.Body
            $avAppointments[$avAppointments[0][0]][7] = $oItem.Categories
            $avAppointments[$avAppointments[0][0]][8] = $oItem.GlobalAppointmentID
            $avAppointments[$avAppointments[0][0]][9] = $oItem.LastModificationTime
    Next
    $oItem = ""
    $oColItems = ""
    $oFolder = ""
    $oNamespace = ""
    If $avAppointments[0][0] = 0 Then Return SetError(2, 0, 0)
    Redim $avAppointments[$avAppointments[0][0] + 1][10]
    Return $avAppointments
EndFunc
Link to comment
Share on other sites

  • 3 weeks later...

Hi,

I've been trying to use the send mail fucntionality. When I run it the messagebox1.exe is executed but doesn't seem to perform the click on the yes button because it is greyed out (until a progress bar completes). I tried manually hitting yes but I get an @error raised. -2147352567 is the error raised from outlook. Has anyone else had this trouble? I am using outlook 2003.

I modified the send mail function in order to trap the error like this:

MsgBox(1,"test",$iRc)

I don't really understand @ERROR and what it returns. Is there any way to get a textual description of the error rather than just a number? I've done loads of searches for @ERROR but can't find a decent explanation of it

Link to comment
Share on other sites

Thanks for this UDF. Very useful, but I am having some problems I was hoping to get some insight on.

Issue 1)

It looks like this has been mentioned previously in the thread: Trying to access a shared mailbox.

In this bit of code, it appears to be parsing out double backslashes "\\"

If StringLeft($sFolder,2) = "\\" Then 
        $fOtherMailBox = True
        Local $asFolderID = StringSplit(StringMid($sFolder,3),"\\",1)
        _Arraydisplay($asFolderID)

and then here it tries to access the folder using GetFolderFromID

If $fOtherMailBox = True Then
        Local $oSession = $oOutlook.Session
        $oFolder = $oSession.GetFolderFromID($asFolderID[1], $asFolderID[2])
        msgbox(0,"obj",isobj($oFolder))
    EndIf

Now I'm probably totally wrong, but from my research, those two parameters should be the EntryID and StoreID, which is not the same as the folder name? Also, unless you pass a folder directory as "\\Folder\\SubFolder" it will not parse into two components.

Reference:

http://msdn.microsoft.com/en-us/library/aa220103%28office.11%29.aspx

I have however been able to get access to the folder via the function PickFolder

$oFolder = $oNamespace.PickFolder

It would be nice to know how to do it without the PickFolder function, but I'll take it for now.

Issue 2)

I'm trying to modify your _OutlookDeleteMail() function so that I can use it to identify mail and do various other functions, aside from deleting. However, even the Delete seems to be inconsistent. The hiccup so far appears to be behind the Restrict() function

If $sFrom <> "" Then
        $sFilter = '[SenderName] = "' & $sFrom & '"'
    EndIf
    If $sSubject <> "" Then
        If $sFilter <> "" Then $sFilter &= ' And '
        $sFilter &= '[Subject] = "' & $sSubject & '"'
    EndIf
    If $sReceivedTime <> "" Then
        If Not _DateIsValid($sReceivedTime) Then Return SetError(1, 0, 0)
        If $sFilter <> "" Then $sFilter &= ' And '
        $sFilter &= '[ReceivedTime] = "' & $sReceivedTime & '"'
    EndIf   
    $oFilteredItems = $oMailItems.Restrict($sFilter)

First of all, you call the _DateIsValid() function from the Date.au3 which looks for a date formatted with delimiters such as yyyy/mm/dd[ hh:mm[:ss]], but the date it retrieves is formatted yyyymmsddhhmmss.

However, I tried a couple other things. For one, I removed the DateIsvalid check. I also tried only passing subject and/or from filters. I have gotten positive matches, but not on every email. I also tried modifying the date to check size instead. In any case, the paramters it uses to filter are not always accurate and I am curious why that might be. Anyone else have this issue that can provide insight?

I am extremely new to this, so maybe I am just not understanding correctly what is going on, but it seems a couple bugs may not be completed ironed out??

Here is what I'm working with so far:

$oOutlook = ObjGet("", "Outlook.Application")
$oNamespace = $oOutlook.Getnamespace("MAPI")
$oFolder = $oNamespace.PickFolder
$oaEmail = _OutlookGetMail($oOutlook, $oFolder)
_OutlookMailAction($oOutlook, $oFolder, $oaEmail[1][1], $oaEmail[1][7])
if @error then
    MsgBox(16, "Error", "Failed to delete Outlook email - " & @ERROR)
    exit
endif

Again, this does not match 100% of emails, even when I try to draft up simple emails for tests and run it through.

Thanks for any help,

Jeff

Link to comment
Share on other sites

I don't see the edit post button, but I just realized I was passing in from the array element [1][1] which was [senderEmailAddress] (what I intended) of the first email, but the function was expecting [senderName] which is element [0]. Once I fixed that, it was working. Also [subject] appears to work anytime there is no RE: or FWD: prefix. Date still does not work. I'll mess with it more unless someone can provide insight. \

It's too bad restrict doesn't accept [EntryID], that would be far and away the most useful property to filter by

Link to comment
Share on other sites

Hi all,

I added two elements to _OutlookSendMail - $sFrom to indicate an alternate username from whom email should be sent (useful for me at work) and HTML-formatted email creation.

I made these additions non-intrusively for backwards compatibility. I think it would be better to add another optional argument (say, $sBodyHTML = "") and auto-set $iBodyFormat properly if a value is passed to that (the ability for non-HTML-friendly mail readers to display the $sBody message in a readable form would be nice), but that led me down the path of rewriting more of the function - I'll leave any refactoring decisions to you.

The three changed or added lines are:

Func _OutlookSendMail($oOutlook, $sTo = "", $sCc = "", $sBcc = "", $sSubject = "", $sBody = "", $sAttachments = "", $iBodyFormat = $olFormatPlain, $iImportance = $olImportanceNormal, $sWarningClick = "C:\Program Files\AutoIt3\Include\OutlookWarning1.exe", $sFrom = "")
...
.SentOnBehalfOfName = $sFrom
...
If $iBodyFormat == $olFormatHTML Then   .HTMLBody = $sBody

Func _OutlookSendMail($oOutlook, $sTo = "", $sCc = "", $sBcc = "", $sSubject = "", $sBody = "", $sAttachments = "", $iBodyFormat = $olFormatPlain, $iImportance = $olImportanceNormal, $sWarningClick = "C:\Program Files\AutoIt3\Include\OutlookWarning1.exe", $sFrom = "")
    Local $iRc = 0, $asAttachments
    If $sTo = "" And $sCc = "" And $sBCc = "" Then
        Return SetError(1, 0, 0)
    EndIf
    If $sWarningClick <> "" And FileExists($sWarningClick) = 0 Then
        Return SetError(2, 0, 0)
    Else
        Run($sWarningClick)
    EndIf
    Local $oOuError = ObjEvent("AutoIt.Error", "_OutlookError")
    Local $oMessage = $oOutlook.CreateItem($olMailItem)
    With $oMessage
        .SentOnBehalfOfName = $sFrom
        .To = $sTo
        .Cc = $sCc
        .Bcc = $sBCc
        .Subject = $sSubject
        .Body = $sBody
        .BodyFormat = $iBodyFormat
        If $iBodyFormat == $olFormatHTML Then   .HTMLBody = $sBody
        
        .Importance = $iImportance
        If $sAttachments <> "" Then 
            $asAttachments = StringSplit($sAttachments,";")
            For $iNumOfAttachments = 1 to $asAttachments[0]
                .Attachments.Add($asAttachments[$iNumOfAttachments])    
            Next
        EndIf
        .Send
        $iRc = @ERROR
    EndWith
    If $iRc = 0 Then
        Return 1
    Else
        Return SetError(9, 0, 0)
    EndIf
EndFunc
Link to comment
Share on other sites

Wooltown,

I just downloaded the UDF and had some problems just getting started. I looked at the _OutlookSendMail demo and code snippets in this thread and whittled down my code to just this:

#Include "Outlook.au3"
$oOutlook = _OutlookOpen()

I got this error from it:

C:\Program Files\AutoIt3\Include\Outlook.au3(1685,3) : ERROR: syntax error

EndIf

^

C:\Program Files\AutoIt3\Include\Outlook.au3(1863,19) : ERROR: 'With' cannot be nested

With $oContact

~~~~~~~~~~~~~~~~~~^

What I found is in the Outlook.au3 file, line 1684 was commented out.

1683 EndIf

1684 ;Endwith

1685 EndIf

I took out the comment line and it seems to work.

Link to comment
Share on other sites

What about adding in options for Categories in Outlook 2007?

I found the categories as an XML stream within PR_FOLDER_ASSOCIATED_CONTENTS Property of the default calendar. Here is an image:

:edit:

pic updated to NOT show my full name... hehe

Edited by ghetek
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...