Jump to content

OutlookEX UDF - Help & Support (IV)


water
 Share

Recommended Posts

You are looking for news mails in a loop. Better check the examples for events that come with the UDF (_OL_Example_NewMailEX). This script waits until a new mail arrives without using any CPU cycles. When a new mail arrives a specified function gets called to process this mail(s).

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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 way to get the latest mail item is described here:

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

Hi,

I got a friend to help me with the code,
So now it should be more manageable. ( I could do better. :)

We have made it so that it now sorts and selects the oldest mails first.
And that we print files by name. with the lowest number / date first.

I will post a new version once I have tested it.
But here is my code at the moment.
Suggestions are welcome. 

Print Outlook attachments1.7.au3

Link to comment
Share on other sites

I would change

If FileExists("C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe") Then
        If $DebugOn = 1 Then ConsoleWrite("Adobe 32Bit print: " & $vFileName & " ")
        If $DebugOn = 1 Then _WriteErrorLog("Adobe 32Bit print: " & $vFileName)
        If $DebugOn = 1 Then _WriteErrorLog('"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /h /p "' & $sSaveDir & $vFileName)
        If $DebugOn = 1 Then ConsoleWrite('"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /h /p "' & $sSaveDir & $vFileName & '" ')
        Local $iPID = Run('"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /h /p "' & $sSaveDir & $vFileName & '" ',"",@SW_MINIMIZE)
        sleep(6500)
        ProcessClose($iPID)

to

If FileExists("C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe") Then
        If $DebugOn = 1 Then 
            ConsoleWrite("Adobe 32Bit print: " & $vFileName & " ")
            _WriteErrorLog("Adobe 32Bit print: " & $vFileName)
            _WriteErrorLog('"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /h /p "' & $sSaveDir & $vFileName)
            ConsoleWrite('"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /h /p "' & $sSaveDir & $vFileName & '" ')
        EndIf
        Local $iPID = Run('"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /h /p "' & $sSaveDir & $vFileName & '" ',"",@SW_MINIMIZE)
        sleep(6500)
        ProcessClose($iPID)

And all other occurrences in your script.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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...

Dear water and Forum moderators,

My company has switched from using Outlook to the messaging system called HubSpot, and I was able to handle the transactions easily using the attached scenario before.

Could you please help me to produce a scenario for use in HubSpot? 

 

#include <OutlookEX.au3>


Func _WinWaitActivate($title,$text,$timeout=0)
   WinWait($title,$text,$timeout)
   If Not WinActive($title,$text) Then WinActivate($title,$text)
   WinWaitActive($title,$text,$timeout)
EndFunc

Opt('TrayIconDebug', 1)
   Opt("WinTitleMatchMode", 2)
   _WinWaitActivate("Satis Teklifi ","")
   Local $sText = WinGetTitle("[ACTIVE]")
   $sText=StringMid($sText,17,9)
;Sorgulama ekranı getiriliyor.



   sleep(3000)

MouseClick($MOUSE_CLICK_LEFT,1122 , 247, 1)

sleep(3000)

MouseClick($MOUSE_CLICK_RIGHT,1122 , 247, 1)

sleep(1000)
 send("{TAB 5}")

 sleep(1000)


Send("{ENTER}")
sleep(1000)

 _WinWaitActivate("Hızlı Rapor Sorgusu: 015 - SSH Teklif - IFS Applications","")
  sleep(2000)


send("{TAB 5}")
  Send("{ENTER}")

;teklif pdf ı görselı

sleep(1000)

  _WinWaitActivate("015 - SSH Teklif ","")

sleep(1000)


;burdamı hata bak
 MouseClick($MOUSE_CLICK_LEFT,67 , 98, 1)

sleep(2000)
  send("{TAB}")
 sleep(1000)
 Send("{ENTER}")
 sleep(1000)
 _WinWaitActivate("Raporu Dışa Aktar","")
 sleep(2000)
Send("{TAB 5}")
   Send("{ENTER}")
  Send("C:\Users\mdogru\Desktop\IFS ÇIKTILARI")
  sleep(500)
  MouseClick($MOUSE_CLICK_LEFT,311 , 75, 1)
sleep(500)
 Send("{ENTER}")
sleep(500)
 MouseClick($MOUSE_CLICK_LEFT,446 , 418, 1)
  sleep(500)

   MouseClick($MOUSE_CLICK_LEFT,459 , 451, 1)
  sleep(500)
;türü sec pdf
 MouseClick($MOUSE_CLICK_LEFT,358 , 396, 1)
  sleep(500)


 Send("DURMAZLAR_TEKLİF")
 sleep(500)
Send("{ENTER}")

 _WinWaitActivate("Farklı Kaydetmeyi Onayla","")
 send("{TAB}")
 sleep(1000)
 Send("{ENTER}")


 _WinWaitActivate("Raporu Dışa Aktar","")

Send("{ENTER}")
sleep(1000)


MouseClick($MOUSE_CLICK_LEFT,25 , 44, 1)
sleep(50)
 _WinWaitActivate("Satis Teklifi -","")



MouseClick($MOUSE_CLICK_LEFT,181 , 120, 2)
sleep(2000)
   ;1 veri kopyalanıyor ,1. copy to the subject okkkkk...
   Send("^C")
   sleep(1000)




;Now please help to copy the data to the email subject section,şimdi email konu kısmına veri kopyalama işlemi için lütfen yardım ,


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

; Access the currently displayed mail item
$oInspector = $oOutlook.ActiveInspector
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error accessing ActiveInspector. @error = " & @error & ", @extended = " & @extended)
$oItem = $oInspector.CurrentItem
$sSubject = ClipGet()
_OL_ItemModify($oOutlook, $oItem, Default, "Subject=" & $sSubject)


If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error accessing current item. @error = " & @error & ", @extended = " & @extended)
If $oItem.Class <> $olMail Then Exit MsgBox(16, "OutlookEX UDF", "Current item isn't a mail item. @error = " & @error & ", @extended = " & @extended)

; Add a PDF file
$sAttachment  ="C:\Users\mdogru\Desktop\IFS ÇIKTILARI\"&"DURMAZLAR_TEKLİF.pdf"
_OL_ItemAttachmentAdd($oOutlook, $oItem, Default, $sAttachment)

; Change <Test.pdf> to the name of your PDF file - or change the whole path if the fil is stored in a different directory.





If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error adding attachment to mail item. @error = " & @error & ", @extended = " & @extended)



; Display item
$oItem.Display

 

TEKLİF 25 03 2021.au3

Edited by mustilem23
flod
Link to comment
Share on other sites

@water,

I think I found a tiny bug? Or I just missed something but looking at the UDF:

Func _OL_ItemAttachmentAdd($oOL, $vItem, $sStoreID, $vP1, $vP2 = "", $vP3 = "", $vP4 = "", $vP5 = "", $vP6 = "", $vP7 = "", $vP8 = "", $vP9 = "", $vP10 = "", $sDelimiter = ",")
    If $sDelimiter = Default Then $sDelimiter = ","

But the description mentions that default delimited is ;

; #FUNCTION# ====================================================================================================================
; Name...........: _OL_Wrapper_SendMail
; Description ...: Creates and sends a mail (wrapper function).
; Syntax.........: _OL_Wrapper_SendMail($oOL[, $sTo = ""[, $sCc= ""[, $sBCc = ""[, $sSubject = ""[, $sBody = ""[, $sAttachments = ""[, $iBodyFormat = $olFormatUnspecified[, $iImportance = $olImportanceNormal]]]]]]]])
; Parameters ....: $oOL          - Outlook object returned by a preceding call to _OL_Open()
;                  $sTo          - [optional] The display name of the recipient(s), separated by ;
;                  $sCc          - [optional] The display name of the CC recipient(s) of the mail, separated by ;
;                  $sBCc         - [optional] The display name of the BCC recipient(s) of the mail, separated by ;
;                  $sSubject     - [optional] The Subject of the mail
;                  $sBody        - [optional] The Body of the mail
;                  $sAttachments - [optional] Attachments, separated by ;

Just a heads up. The reason why I posted this is because I kept getting a @error=5004 and I think it's because the file has a comma in it.

 

Nope, even after changing the , to a ; I still get an 5004 error. Weird, maybe it's not a bug.

Edited by BatMan22
Link to comment
Share on other sites

; is correct for all parameters of _OL_Wrapper_SendMail. When calling _OL_ItemAttachmentAdd parameter $sDelimiter is set to Default (= ,).
This delimiter is only used to split a string with multiple recipients. As _OL_Wrapper_SendMail passes an array of recipients $sDelimiter isn't used in _OL_ItemAttachmentAdd .

It is a kind of bug as such delimiters should be consistent for all functions. 
If needed I could modify the UDF to accept , ; or both as separators.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

5004 means: Attachment not found.
How do you specify the attachment to add?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

Hi @water,

Turns out I'm an idiot, the pdf I am attempting to email is being written to in the step immediately before sending this email. File is just busy apparently and a pause has fixed my issue. Will leave this here for anyone else that runs into this to know that Error 5004 can also mean file busy / file not found.

Link to comment
Share on other sites

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

@water

Actually I definitely think is a bug. I stand by my comment about being an idiot but when adding an attachment with a "," in the name, it does get split up. I added an array to show $aTemp with and without hard coding the delimiter: 

 

 

Func _OL_ItemAttachmentAdd($oOL, $vItem, $sStoreID, $vP1, $vP2 = "", $vP3 = "", $vP4 = "", $vP5 = "", $vP6 = "", $vP7 = "", $vP8 = "", $vP9 = "", $vP10 = "", $sDelimiter = ",")
;~  If $sDelimiter = Default Then $sDelimiter = ","
    $sDelimiter = ";" ;Works
;~  $sDelimiter = "," ;Doesn't work
    Local $aAttachments[10]
    If Not IsObj($vItem) Then
        If StringStripWS($vItem, BitOR($STR_STRIPLEADING, $STR_STRIPTRAILING)) = "" Then Return SetError(1, 0, 0)
        $vItem = $oOL.Session.GetItemFromID($vItem, $sStoreID)
        If @error Then Return SetError(2, @error, 0)
    EndIf
    ; Move attachments into an array
    If Not IsArray($vP1) Then
        $aAttachments[0] = $vP1
        $aAttachments[1] = $vP2
        $aAttachments[2] = $vP3
        $aAttachments[3] = $vP4
        $aAttachments[4] = $vP5
        $aAttachments[5] = $vP6
        $aAttachments[6] = $vP7
        $aAttachments[7] = $vP8
        $aAttachments[8] = $vP9
        $aAttachments[9] = $vP10
    Else
        $aAttachments = $vP1
    EndIf
    ; Add attachments to the item
    For $iIndex = 0 To UBound($aAttachments) - 1
        If $aAttachments[$iIndex] = "" Or $aAttachments[$iIndex] = Default Then ContinueLoop
        Local $aTemp = StringSplit($aAttachments[$iIndex], $sDelimiter)
        _ArrayDisplay($aTemp)
        ReDim $aTemp[5] ; Make sure the array has 4 elements (element 2-4 might be empty)

 

image.png

Link to comment
Share on other sites

A quick and dirty fix could be to modify _OL_Wrapper_SendMail:

_OL_ItemAttachmentAdd($oOL, $oItem, Default, $aAttachments)

with

_OL_ItemAttachmentAdd($oOL, $oItem, Default, $aAttachments, Default, Default, Default, Default, Default, Default, Default, Default, Default, ";")

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

  • 1 month later...

Yes. #RequireAdmin starts a new process as Admin with elevated permissions. Outlook needs to be started by the user who runs the script. 
please have a look at the wiki. 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

  • 3 weeks later...

Version 1.7.0.0 of the UDF has been released.

Now you get a help file that looks like the AutoIt help.

Please test before using in production!

For download please see my signature.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

  • 1 month later...

When using the below code snippet , I only expect to get appointments for 2/18.

 

I have recurring appointments and it seems to include those in the results  , so for an example I have a recurring one that was built on 5/6/2021 and it is included when i run the below find , but is not scheduled for 2/18/2022.

 

Global $aAppointments = _OL_ItemFind($oOutlook, "*\Calendar", $olAppointment, "[Start]>='2022-02-18 00:00' And [End]<='2022-02-18 23:59'", "", "", "EntryID,Subject,Body,ConversationTopic,Start", "", 2)

What am I missing

Link to comment
Share on other sites

Does the recurrence define an appointment for 2022-02-18 which later has been deleted or moved?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

×
×
  • Create New...