Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

OutlookEX UDF - Help & Support


  • This topic is locked This topic is locked
634 replies to this topic

#421 mdcastle

mdcastle

    Wayfarer

  • Active Members
  • Pip
  • 65 posts

Posted 23 May 2012 - 03:53 PM

Great - thanks.







#422 water

water

    ?

  • MVPs
  • 15,730 posts

Posted 23 May 2012 - 03:54 PM

You are welcome ;)
UDFs:
Active Directory (NEW 2014-07-21 - Version 1.4.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

#423 mdcastle

mdcastle

    Wayfarer

  • Active Members
  • Pip
  • 65 posts

Posted 29 May 2012 - 02:31 PM

water

Hoping you can help with an Attachment Save problem i have.

I have the following code which checks for the type of attachment and if it is not a PDF it processes an action, either deleting the attachment or saving it.

I'm using _OL_ItemAttachmentSave, but there may be attachments with the same name, so I tried to use _OL_ItemSave, but I can't figure out where in my code _OL_ItemSave should go.

AutoIt         
Global $sFilter = "@SQL=(""urn:schemas:httpmail:hasattachment"" = 1 AND ""urn:schemas-microsoft-com:office:office#Keywords"" = 'AutoIT')" Global $aResult = _OL_ItemSearch($oOutlook, $aFolder[1], $sFilter, "EntryID,subject") If @error Then     MsgBox(16, "Searching", "Error Searching Marketplace InvoicesInbox for emails with attachments and the 'AutoIT' category. @error = " & @error & ", @extended = " & @extended)     Exit Else     traytip("Searching", "Searching for non-PDF attachments and marking them with the 'Non-PDF' category", 30, 1)     Sleep(2000) EndIf ; Get a list of attachments and save non-PDF attachments for changing to PDFs For $i = 1 To $aResult[0][0] ConsoleWrite($aResult[$i][1] & @CRLF) $aAttachments = _OL_ItemAttachmentGet($oOutlook, $aResult[$i][0]) For $j = 1 To $aAttachments[0][0]   If StringRegExp($aAttachments[$j][2], "pdf$|PDF$") Then    ConsoleWrite("  " & $aAttachments[$j][2] & @CRLF)   ElseIf StringRegExp($aAttachments[$j][2], "mht$|txt$|png$") Then    _OL_ItemAttachmentDelete($oOutlook, $aResult[$i][0], Default, $aAttachments[0][0])    If @error <> 0 Then MsgBox(16, "Error", "Error deleting attachments from email. @error = " & @error & ", @extended = " & @extended)   Else    _OL_ItemAttachmentSave($oOutlook, $aResult[$i][0], Default, $aAttachments[0][0], $SavePath & "" & $aAttachments[$j][2])    ;_OL_ItemSave($oOutlook, $aResult[$i][0], Default, $SavePath & "", $olHTML, 2)    If @error <> 0 Then MsgBox(16, "Error", "Error saving attachments to PDFConversionArea folder. @error = " & @error & ", @extended = " & @extended)    ;Set 'Non-PDF' category    _OL_ItemModify($oOutlook, $aResult[$i][0], Default, "Categories=Non-PDF", "UnRead=False" )    If @error <> 0 Then Exit MsgBox(16, "Update Category", "Error marking item with 'Non-PDF' category. @error = " & @error & ", @extended = " & @extended)   EndIf Next Next


To be clear the attachment should only be saved if it is not a PDF.

#424 water

water

    ?

  • MVPs
  • 15,730 posts

Posted 29 May 2012 - 02:38 PM

Change line
_OL_ItemAttachmentSave($oOutlook, $aResult[$i][0], Default, $aAttachments[0][0], $SavePath & "" & $aAttachments[$j][2])
to
_OL_ItemAttachmentSave($oOutlook, $aResult[$i][0], Default, $j, $SavePath & "" & $aAttachments[$j][2])
You specified the total number of attachments in the mail but you need to specify the index of the attachment to save.
UDFs:
Active Directory (NEW 2014-07-21 - Version 1.4.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

#425 mdcastle

mdcastle

    Wayfarer

  • Active Members
  • Pip
  • 65 posts

Posted 30 May 2012 - 11:09 AM

Thanks water

Another problem I have come across when using _OL_ItemAttachmentSave is an attachment with the same name, but attached to a separate email e.g. Email 1 with attachment named 'attachment1.pdf' and Email 2 with attachment named 'attachment1.pdf'.

Do you have any idea how I can get round this, as at the moment I get error code 4 when using _OL_ItemAttachmentSave.

Many thanks in advance.

#426 storme

storme

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 850 posts

Posted 30 May 2012 - 11:45 AM

HI Water

I'm trying to write a little script to Email customers from my Outlook Contacts.

Basic steps
Querry contacts - Customers that I haven't seen for 12 months
Send an Email.
Add to the NOTES field that an email was sent

But I've hit a snag at the first step.
I can't work out how to query with a range of dates.

I think it should be something liek this.
Local $sStartDate = "???????" ' Start of range to extract Local $sEndtDate = "???????" ' End of range to extract Local $aItems = _OL_ItemFind($oOutlook, $oOL_ContactFolder, $olContact, _    '[JobTitle] = "Customer" and [Anniversary] > "' & $sStartDate & '" and [Anniversary] < "' & $sEndDate & '"', "", "", _    "EntryID,FullName,CompanyName,Anniversary,Email2Address,Email1Address,Email3Address", "", 1)

I'm not sure what format the "$sStartDate" and "$sEndtDate" should be and should the dates be enclosed in inverted commas in the query.

Any help would be appreciated! Thanks
John Morrison

Edit: answered a stupid question myself so I deleted it to cover it up. ;)

Edited by storme, 30 May 2012 - 11:48 AM.


#427 water

water

    ?

  • MVPs
  • 15,730 posts

Posted 30 May 2012 - 12:13 PM

Another problem I have come across when using _OL_ItemAttachmentSave is an attachment with the same name, but attached to a separate email e.g. Email 1 with attachment named 'attachment1.pdf' and Email 2 with attachment named 'attachment1.pdf'.

You could do a
FileExists($SavePath & "" & $aAttachments[$j][2])
before calling _OL_ItemAttachmentSave. If the file already exists pass another path/filename as parameter $sOL_Path.

Edited by water, 30 May 2012 - 12:14 PM.

UDFs:
Active Directory (NEW 2014-07-21 - Version 1.4.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

#428 storme

storme

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 850 posts

Posted 30 May 2012 - 12:13 PM

Not sure if anyone has posed this.
http://www.microeye.com/resources/ObjectModel.htm

it's a VERY LARGE PDF/Visio diagram that contains all the objects in outlook and how they interconnect.
It's great for a birds-eye-view and how everything intereconnects.

Hope it helps someone.

John Morrison

#429 water

water

    ?

  • MVPs
  • 15,730 posts

Posted 30 May 2012 - 12:20 PM

I found this great diagram when I started to search for info on the Outlook COM Model. MS has something similar but - as it is written by MS - it is completely useless.
The object model you posted is for Outlook 2000.
Here is the Outlook 2003 version.
UDFs:
Active Directory (NEW 2014-07-21 - Version 1.4.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

#430 water

water

    ?

  • MVPs
  • 15,730 posts

Posted 30 May 2012 - 12:24 PM

When searching for mails I use the following format:
Local $sStartDate = "2011-02-21 08:00" Local $sEndtDate = "2012-02-21 08:00"

Example can be found here.
UDFs:
Active Directory (NEW 2014-07-21 - Version 1.4.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

#431 storme

storme

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 850 posts

Posted 30 May 2012 - 12:30 PM

I found this great diagram when I started to search for info on the Outlook COM Model. MS has something similar but - as it is written by MS - it is completely useless.
The object model you posted is for Outlook 2000.
Here is the Outlook 2003 version.


Thanks! those files are so big I didn't notice what version it was...DOH! ;)

#432 storme

storme

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 850 posts

Posted 30 May 2012 - 12:34 PM

When searching for mails I use the following format:

Local $sStartDate = "2011-02-21 08:00" Local $sEndtDate = "2012-02-21 08:00"

Example can be found here.

DAM! Sorry about that I have ALL the HELP files here and looked at that one and just plain didn't see that.

So a second SORRY for the day!!! ;)

Edited by storme, 30 May 2012 - 12:35 PM.


#433 water

water

    ?

  • MVPs
  • 15,730 posts

Posted 30 May 2012 - 12:41 PM

No problem ;)
I myself get lost sometimes in the piles of code and documentation I write ...
UDFs:
Active Directory (NEW 2014-07-21 - Version 1.4.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

#434 storme

storme

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 850 posts

Posted 30 May 2012 - 01:57 PM

When searching for mails I use the following format:

Local $sStartDate = "2011-02-21 08:00" Local $sEndtDate = "2012-02-21 08:00"

Example can be found here.

I tried that and I can't get it to work. :)

After the Range didn't work I decided to try and extract just one item.
The Customer has an Anniversary field = "20120524000000" 2012-05-24
This is the code I came up with.
 Local $sStartDate = "2012-05-24 00:00" ; Start of range to extract  ;Local $sEndtDate = "2011-05-30 00:00" ; End of range to extract  Local $aItems = _OL_ItemFind($oOutlook, $oOL_ContactFolder, $olContact _    ,'[JobTitle] = "Customer" And [Anniversary] = "' & $sStartDate & '"' _    , "", "" _    ,"EntryID,FullName,CompanyName,Anniversary,Email2Address,Email1Address,Email3Address", "", 1)  If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemModify Example Script", "Error modifying a contact in folder 'Outlook-UDF-TestSourceFolderContacts'. @error = " & @error)  _ArrayDisplay($aItems)


I also tried (used the > and made the date one day less
 Local $sStartDate = "2012-05-23 00:00" ; Start of range to extract  ;Local $sEndtDate = "2011-05-30 00:00" ; End of range to extract  Local $aItems = _OL_ItemFind($oOutlook, $oOL_ContactFolder, $olContact _    ,'[JobTitle] = "Customer" And [Anniversary] > "' & $sStartDate & '"' _    , "", "" _    ,"EntryID,FullName,CompanyName,Anniversary,Email2Address,Email1Address,Email3Address", "", 1)  If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemModify Example Script", "Error modifying a contact in folder 'Outlook-UDF-TestSourceFolderContacts'. @error = " & @error)  _ArrayDisplay($aItems)


I even tried (amoungst other things)
 Local $sStartDate = "20120524000000" ; Start of range to extract  ;Local $sEndtDate = "2011-05-30 00:00" ; End of range to extract  Local $aItems = _OL_ItemFind($oOutlook, $oOL_ContactFolder, $olContact _    ,'[JobTitle] = "Customer" And [Anniversary] = "' & $sStartDate & '"' _    , "", "" _    ,"EntryID,FullName,CompanyName,Anniversary,Email2Address,Email1Address,Email3Address", "", 1)  If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemModify Example Script", "Error modifying a contact in folder 'Outlook-UDF-TestSourceFolderContacts'. @error = " & @error)  _ArrayDisplay($aItems)

and still got nothing.

I can just extract the whole data then crawl thorugh the array. However, it woudl be much more elegant if I could get Outlook to do ti for me. ;)
I've got to be missing something but I just don't know what.
BTW if I remove the "Anniversary" condition I get an array containing all the customers....sigh

#435 water

water

    ?

  • MVPs
  • 15,730 posts

Posted 30 May 2012 - 02:16 PM

I tried here (German Outlook 2010) and the following selections work:
$sStartDate = "2012-05-30" $sStartDate = "30.5.2012" $sStartDate = "30.05.2012" $sStartDate = "31 May, 2012" $sStartDate ="05/30/2012" ; MMDDYYYY depending on the locale

Edited by water, 30 May 2012 - 02:36 PM.

UDFs:
Active Directory (NEW 2014-07-21 - Version 1.4.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

#436 water

water

    ?

  • MVPs
  • 15,730 posts

Posted 30 May 2012 - 02:28 PM

A good reading is this article.
UDFs:
Active Directory (NEW 2014-07-21 - Version 1.4.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

#437 storme

storme

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 850 posts

Posted 30 May 2012 - 02:35 PM

I tried here (German Outlook 2010) and the following selections work:

$sStartDate = "2012-05-30" $sStartDate = "30.5.2012" $sStartDate = "30.05.2012" $sStartDate = "31 May, 2012"

AHHHH so it was the TIME that didn't need to be there!
Makes sense but as you stated earlier you use the time (eg "2011-02-21 08:00") when searching for Emails so I assumed that it would be consistant.
Sigh....

Thanks for working that out for me!!!

#438 water

water

    ?

  • MVPs
  • 15,730 posts

Posted 30 May 2012 - 02:38 PM

I hate the different formats for dates you can use in MS Office products plus the locale dependant variations.
www.outlookcode.com describes quite good how it is supposed to work ;)
UDFs:
Active Directory (NEW 2014-07-21 - Version 1.4.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

#439 water

water

    ?

  • MVPs
  • 15,730 posts

Posted 31 May 2012 - 09:19 AM

Is it posible to get out all Mapi Profile's?

The list of profiles is stored in the registry:
"HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook" or
"HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles" depending on the Outlook version.
  • Spenhouet likes this
UDFs:
Active Directory (NEW 2014-07-21 - Version 1.4.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

#440 Spenhouet

Spenhouet

    Seeker

  • Active Members
  • 37 posts

Posted 31 May 2012 - 10:02 AM

Thx this works fine ;)

Is it possible to create a new mapi outlook profile? how?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users