Jump to content

Outlook COM


J_Y_C
 Share

Recommended Posts

Ok, so I have been trying to understand how to use a Outlook COM object.

I have a TON of questions about this, and you guys are the only ones I know

that I can ask. Anywho, let me start with an "easy" one:

According to the helpfile, I need to use the VersionIndependentProgID for a COM object, which in the case of Outlook is "OVCtl.OVCtl".

But, everywhere I've looked in the forum, anyone else who creates an outlook object uses "Outlook.Application". Why is that? I couldn't find a VersionIndependentProgID that says "outlook.application" anywhere.

TIA to anyone that can help me with this. If there is someone who is really familiar with COM objects that wouldn't mind a barrage of stupid questions, I would be most greatful.

Or, if there is someone working on an Outlook UDF please PM me, maybe I could help you in some way if you can help me?

Link to comment
Share on other sites

Here is a place to start for Outlook Automation at MSDN

I'm not familiar with the Ovctl.Ovctr interface...

Version independat means that you use Outlook.Application instead of, say, Outlook.Application.9

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Well, what I would like to do is be able to automatically save any incoming e-mail with some specific words in the title as a file.

It seems like it should be totally easy to do, I've used the WM objects with some good results, but I just can't get this to work.

Edited by J_Y_C
Link to comment
Share on other sites

Well, that's kind of tricky actually. The part that does something special based on the contents of the message was already written by Microsoft - the Rules Wizard :P . What I would propose you do is this:

1. Set up a Outlook Rule based on incoming subject text

2. Have it move the message to a sub folder of the Inbox, say "AI"

3. Have it set a category to something, say "AutoItFlag"

Then write a little script to spin through that folder every 60 seconds, looking for messages that have that flag set. Like this:

Global Const $olFolderInBox = 6

$ol = ObjCreate ("Outlook.Application")
$ns = $ol.GetNameSpace("MAPI")
$AIItems = $ns.GetDefaultFolder($olFolderInBox).Folders.item("AI").Items

while 1
    ; go through them in reverse order - required if you delete anything
    for $position = $AIItems.Count to 1 step -1 

        $message = $AIItems.Item($position)
    
        if stringinstr($message.Categories,"AutoItFlag") then
            msgbox(0,$message.Subject,$message.Body)
            $message.Categories = ""
            $message.Save()

            ;if you want to remove the message instead, just delete it, like so:
            ;$message.Delete()
        endif

    next
    sleep(60*1000) ; wait sixty seconds and check for new messages
wend

Note that Outlook thinks this sort of thing is dangerous, so you may get a security prompt.

Edited by lod3n

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

Wow, thanks a ton, I really appreciate it. I never know which objects to instantiate, and it seems like anytime you make a COM object, you have to create a bunch of others to get to the one you want.

This gives me a great starting point. Just out of curiosity though, did this code work for you?

I keep getting this error:

C:\xxxxxx\test.au3 (5) : ==> The requested action with this object has failed.: 
$AIItems = $ns.GetDefaultFolder($olFolderInBox).Folders.item("AI").Items 
$AIItems = $ns.GetDefaultFolder($olFolderInBox).Folders.item("AI")^ ERROR

At first I thought it might be because it was not finding any subject titles with "AI", so I changed it to reflect messages that were actually in my inbox. But, I still get the error. I thought perhaps you had to put .....item("AI") into a handle, and then get the .Items from that:

$item = $ns.GetDefaultFolder($olFolderInBox).Folders.item("AI")
$AIItems = $item.Items

But that give me this error:

C:\xxxxxx\test.au3 (5) : ==> The requested action with this object has failed.: 
$item = $ns.GetDefaultFolder($olFolderInBox).Folders.item("AI") 
$item = $ns.GetDefaultFolder($olFolderInBox).Folders.item("AI")^ ERROR

So, I think the problem is something to do with the .item("AI") part.....

Edited by J_Y_C
Link to comment
Share on other sites

Ohhhhhhhhhhhhhhhhhhhhhh MG awesome.

Thanks a mil, it works like a charm!!!!!

Thanks to you and Dale for your much needed advice. I don't know what I would do without this forum. :P

Edited by J_Y_C
Link to comment
Share on other sites

  • 3 months later...

@lod3n

I want to write a script that will search through a PST file and remove all the attachments.

I think I can use the script that you did for J_Y_C as a starting point, however I need to be able to identify all the folders that contain messages rather than explicitly specify an individual folder. Are you able to offer any pointers on how to achieve this?

I have been looking at MSDN and maybe I am not looking in the right area, but while I can find info about Outlook generally I am having a lot of trouble trying to establish which method I should be using. I'm a bit lost at the moment, so any tips would be helpful.

Thanks

VW

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...