Jump to content

Outlook UDF


Wooltown
 Share

Recommended Posts

  • 3 weeks later...

Hi

Thank you for your great work !!

Is it much work to implement a little funktion like

_OutlookCountUnreadMail($oOutlook,$olFolderInbox) ?

Because if you have a big Mailbox with many unread mails the whole funktion

_OutlookGetMail($oOutlook,$olFolderInbox,False,"","","","","","",True,"",0) needs a lot of time (because of _OutlookFindMailInTree)

if you only want to know if there are some new mail.

I want to check the count of unread mails in the loginscript....

Regards

Martin

Link to comment
Share on other sites

Geting an error and ran out of ideas and was unable to find it in a search.

#include <Outlook.au3>
#include <Array.au3>

$oOutlook = _OutlookOpen()
$A = _OutlookGetMail($oOutlook)
_ArrayDisplay($A)
ConsoleWrite($A)

And when i run that, i get one of these.

Outlook.au3 (514) : ==> Error in expression.:

Local $oNamespace = $oOutlook.GetNamespace("MAPI")

Local $oNamespace = ^ ERROR

any ideas?

Link to comment
Share on other sites

Hi Bam

-Are you shure your actual useraccount has an correct configured outlook profile ?

-Did you answer the messagebox wich controls the access to the profile with yes ?

-Is your Autoit Version 3.1.1 or higher

-Check successfull open of the new Object:

$oOutlook = _OutlookOpen()
If $oOutlook <> 0 then 
   $A = _OutlookGetMail($oOutlook)
   _ArrayDisplay($A)
   ConsoleWrite($A)
EndIf

If you want to check the error please have a look in Outlook.au3, go to the funktion _OutlookGetMail and read the remarks

by the way

you do not need to include Array.au3 its already inluded in outlook.au3

Edited by mko
Link to comment
Share on other sites

Well I tried it on this computer first and I dont get that error but $A returns 0.

The other computer has the default Outlook by xp so I went back to the computer that dosnt give the error.

-Are you shure your actual useraccount has an correct configured outlook profile ?

Yup I can send and recieve emails if thats what you mean.

-Did you answer the messagebox wich controls the access to the profile with yes ?

Not shure on this one, looked around in options and didn't find any thing.

<Edit> Hey just found a push and recieve COM thingy :) *restart outlook* and what do you know it works :party: ty </>

(Using Outlook 2007)

-Is your Autoit Version 3.1.1 or higher

Both are 3.3.0.0

And I saw that Array.au3 was already inluded in outlook.au3 but i thought id just leave it.

Edited by Bam
Link to comment
Share on other sites

  • 3 weeks later...

mko:

I will check if it is easy to do this function

_OutlookCountUnreadMail($oOutlook,$olFolderInbox) ?

But I think the function will take some time to run if you have many mail.

Done - And it is fast !!!!!

I changed the _OutlookGetMail() function and added a parameter $fCountMailOnly, setting this to True will return a small array displaying the total number of items and the number of unread items.

[0][0] - Total Number of items

[0][1] - Number of unread items

Edited by Wooltown
Link to comment
Share on other sites

  • 4 weeks later...

Excerpt from Script:

; Function Name: _OutlookGetMail()

; Description: Get all email using Microsoft Outlook.

; Syntax.........: _OutlookGetMail($oOutlook, $sFolder = $olFolderInbox, $fSubFolder = False, $sFrom = "", $sTo = "", $sCc = "", $sBCc = "", $sSubject = "", $iImportance = "", $fOnlyReturnUnread = False, $sWarningClick = "", $iSetStatus = 0, $fCountMailOnly = False)

; Parameter(s): $oOutlook - Outlook object opened by a preceding call to _OutlookOpen()

; $sFolder - Optional: Folder, default = $olFolderInbox, add subfolders if wish to start search at a lower level, ex: $olFolderInbox & "\Archive"

; If you wish to access the root, use "\", Sent Items, write "\Sent Items"

Or was it some other way you want ?

Link to comment
Share on other sites

I'm having trouble to get to the lower level mailbox

In the picture I uploaded you can see that (it's in Dutch, but you'll understand) that RLB is the default mailbox.

I'm trying to read a subfolder from another Mailbox (Info==>Inbox==>Testfolder)

post-22779-1246616119_thumb.jpg

post-22779-1246616120_thumb.jpg

Link to comment
Share on other sites

IQ9003, Here is a beta version, test if it works, I don't have the possibility to test to read another persons mailbox.

I tested towards a pst-file, but there I can't locate the standard inbox.

To access another mailbox, start with 2 \\, see the example file in the zip-file

OutlookBeta.zip

Edited by Wooltown
Link to comment
Share on other sites

I've tried the code however I can't get it to work.

I'm not sure what the problem is, but I beleive it's in the following piece of code.

(Iv'e checked all variables until this piece, I don't know how to check the rest of the code)

If $fOtherMailBox = True Then
        Local $oSession = $oOutlook.Session
        Local $oMailBox = $oSession.CreateRecipient($sOtherMailBox)
        $oMailBox.Resolve
        Local $oFolder = $oNamespace.GetSharedDefaultFolder($oMailBox,$olFolderInbox)
        Local $sFolderName = $oFolder.Parent
            For $idx = 1 To $sFolderName.Folders.Count
            If $sFolderName.Folders.Item($idx).Name = $sFolder Then $oFolder = $sFolderName.Folders.Item($idx)
        Next
    EndIf
Link to comment
Share on other sites

Hello,

I've made some progress on my own script in which I've managed to move a mail form mailbox1 to mailbox2 (including the subfolders I asked about).

With the code you made and some googl'ing I was able to construct the following code:

$teller=SaveAndMove("Mailbox User1\Inbox","Mailbox User2\Inbox\test")
msgbox(0,"Mail moved","I've moved " & $teller & " mail Items")

Func SaveAndMove($Postbus_old, $Postbus_new)
    $oOApp = ObjCreate("Outlook.Application")
    $myNamespace =$oOApp.GetNamespace("MAPI")
    ; Original folder
    $myarrayold=StringSplit ( $Postbus_old, "\")
    $myOldFolder = $myNamespace.Folders($myarrayold[1])
    For $i=2 to $myarrayold[0]
        $myOldFolder=$myOldFolder.Folders($myarrayold[$i])
    next
    ; Folder to put the mail in
    $myarraynew=StringSplit ( $Postbus_new, "\")
    $myNewFolder = $myNamespace.Folders($myarraynew[1])
    For $i=2 to $myarraynew[0]
        $myNewFolder=$myNewFolder.Folders($myarraynew[$i])
    next
    $teller=0
    ;Countback loop, this is because the mailitem index resets after each move
    For $a=$myOldFolder.Items.count to 1 Step -1
        If $myOldFolder.Items($a).flagicon=3 then
            $teller=$teller+1
            $iAttachCnt = $myOldFolder.Items($a).Attachments.Count
            If $iAttachCnt > 0 Then
                For $iAttachNum = 1 to $iAttachCnt
                    $oTemp = $myOldFolder.Items($a).Attachments.Item($iAttachNum)
                    $sFileName = $oTemp.FileName
                    $oTemp = $myOldFolder.Items($a).Attachments.Item($iAttachNum)
                    if stringinstr($sFileName,".pdf") > 0 then
                        $oTemp.SaveAsFile ("c:\temp\" & $sFileName)
                    endif
                Next
            EndIf
            ;Move mail after saving attachements
            $myoldfolder.Items($a).move ($myNewFolder)
        endif
    next
    return $teller
 endfunc
Edited by IQ9003
Link to comment
Share on other sites

Hello,

I've made some progress on my own script in which I've managed to move a mail form mailbox1 to mailbox2 (including the subfolders I asked about).

With the code you made and some googl'ing I was able to construct the following code:

$teller=SaveAndMove("Mailbox User1\Inbox","Mailbox User2\Inbox\test")
msgbox(0,"Mail moved","I've moved " & $teller & " mail Items")

Func SaveAndMove($Postbus_old, $Postbus_new)
    $oOApp = ObjCreate("Outlook.Application")
    $myNamespace =$oOApp.GetNamespace("MAPI")
    ; Original folder
    $myarrayold=StringSplit ( $Postbus_old, "\")
    $myOldFolder = $myNamespace.Folders($myarrayold[1])
    For $i=2 to $myarrayold[0]
        $myOldFolder=$myOldFolder.Folders($myarrayold[$i])
    next
    ; Folder to put the mail in
    $myarraynew=StringSplit ( $Postbus_new, "\")
    $myNewFolder = $myNamespace.Folders($myarraynew[1])
    For $i=2 to $myarraynew[0]
        $myNewFolder=$myNewFolder.Folders($myarraynew[$i])
    next
    $teller=0
    ;Countback loop, this is because the mailitem index resets after each move
    For $a=$myOldFolder.Items.count to 1 Step -1
        If $myOldFolder.Items($a).flagicon=3 then
            $teller=$teller+1
            $iAttachCnt = $myOldFolder.Items($a).Attachments.Count
            If $iAttachCnt > 0 Then
                For $iAttachNum = 1 to $iAttachCnt
                    $oTemp = $myOldFolder.Items($a).Attachments.Item($iAttachNum)
                    $sFileName = $oTemp.FileName
                    $oTemp = $myOldFolder.Items($a).Attachments.Item($iAttachNum)
                    if stringinstr($sFileName,".pdf") > 0 then
                        $oTemp.SaveAsFile ("c:\temp\" & $sFileName)
                    endif
                Next
            EndIf
            ;Move mail after saving attachements
            $myoldfolder.Items($a).move ($myNewFolder)
        endif
    next
    return $teller
 endfunc

OK, nice, but will it work if you have a folder that is on the same level as Inbox.
Link to comment
Share on other sites

I got it to work with a little help from this topic

http://www.autoitscript.com/forum/index.php?showtopic=80131&st=0&p=576853&hl=outlook&fromsearch=1&#entry576853

I will continue my work of the UDF

This property would be useful, but it only works from Outlook 2007, we are using Outlook 2003.

http://msdn.microsoft.com/en-us/library/bb175607.aspx

Edited by Wooltown
Link to comment
Share on other sites

yes it also works for folders at the same level as the Inbox, but also to other users mailbox.

(We also have Outlook2003)

OK, nice, but will it work if you have a folder that is on the same level as Inbox.

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