Not able to create Outlook Mail Item

Get help with using AutoHotkey and its commands and hotkeys
rynsp8
Posts: 46
Joined: 30 Jan 2018, 12:45

Not able to create Outlook Mail Item

31 May 2019, 08:31

Hello all,

I'm playing with Outlook and AHK. I'm attempting to just create a mail item using the below code.

Code: Select all

ol := ComObjActive("Outlook.Application")
MailItem := ol.CreateItem(0)
I've been able to find the OllItemTypes https://docs.microsoft.com/en-us/office/vba/api/outlook.olitemtype. When I run the script it doesn't throw any errors, but it also doesn't create the email item as I expect.

Perhaps I'm not accessing the Outlook COM Object correctly?
User avatar
TheDewd
Posts: 1334
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Not able to create Outlook Mail Item

31 May 2019, 09:04

So close... You will need MailItem.Display to make it visible.

Code: Select all

#SingleInstance, Force

ol := ComObjActive("Outlook.Application")
MailItem := ol.CreateItem(0)
MailItem.Display

More examples: https://autohotkey.com/board/topic/71335-mickers-outlook-com-msdn-for-ahk-l/
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
rynsp8
Posts: 46
Joined: 30 Jan 2018, 12:45

Re: Not able to create Outlook Mail Item

31 May 2019, 10:03

Can you elaborate on the NameSpace property? Online, on Microsoft's website, it states, "The object itself provides methods for logging in and out, accessing storage objects directly by ID, accessing certain special default folders directly, and accessing data sources owned by other users."

Am I to believe that I need to use GetNameSpace to access folders and emails within my account? Or, if I already have Outlook open, I can continue to manipulate it with ComObjActive("Outlook.Application")?
User avatar
Datapoint
Posts: 68
Joined: 18 Mar 2018, 17:06

Re: Not able to create Outlook Mail Item

31 May 2019, 13:29

rynsp8 wrote:
31 May 2019, 10:03
Am I to believe that I need to use GetNameSpace to access folders and emails within my account? Or, if I already have Outlook open, I can continue to manipulate it with ComObjActive("Outlook.Application")?
Application and NameSpace; you don't just use one or the other. If you want to access a member of the NameSpace then you need them both. First you need to get the NameSpace from the application. Then you can access the members of the namespace.
For example, this gets the NameSpace (pretty much always "MAPI"), then it accesses the "GetDefaultFolder" member of the NameSpace.

Code: Select all

olFolderCalendar := 9
App := ComObjActive("Outlook.Application")
NameSpace := App.Session ; get the namespace. Same as: NameSpace := App.GetNamespace("MAPI")
CalendarFolder := NameSpace.GetDefaultFolder(olFolderCalendar)

Return to “Ask For Help”

Who is online

Users browsing this forum: aifritz, Bing [Bot], inseption86 and 234 guests