Outlook COM: Setting account to send from

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
emretoprak
Posts: 19
Joined: 14 Jun 2017, 07:56

Re: Outlook COM: Setting account to send from

31 Aug 2017, 04:07

Here is my feedback:

Thanks to FanaticGuru for the real quick response and for the help. It works perfectly, presumed the mail account is setup as a separate mail account but not connected to an existing account using "advanced settings". With other words, I could use any of the accounts which can be found using the code written by FanaticGuru.

Now to my second point, is it possible to include a reminder for the emails I generate? (before sending them). Thanks.
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Outlook COM: Setting account to send from

31 Aug 2017, 12:40

emretoprak wrote:@derz00: I mean the reminder function of outlook. In outlook it is possible to set a reminder for an email so that you check the status. It can found under Follow Up --> Add Reminder
Below is a link to the list of properties of an email item.
https://msdn.microsoft.com/en-us/librar ... rties.aspx

I have not tried it but I assume some combination of setting the properties that have to do with reminders or task for an email will do what you want.

Normally just about anything you can do through an email's menu and buttons can be done through the properties. Basically everything that you click in an email's menus and tabs has to be stored and generally there is a property for everything stored about an email that can be set directly through COM.

To figure out what the property needs to look like you can often click the menu items and then have AHK display the value of different properties to see how they change.

A complicating factor is that many properties of an email item are not strings. They are other objects. Attachments is one of the most common. I have never had a need to deal with DateTime but at a glance it looks like an object also which will require unraveling how to properly construct before attempting to use it.
https://msdn.microsoft.com/EN-US/library/03ybds8y

Maybe others have insight on working with DateTime object. At some point I will probably take the time to play around with it and see what I can figure out.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Outlook COM: Setting account to send from

31 Aug 2017, 19:27

After further review creating and sending an email with follow up and task linked to it is fairly complicated.

The problem is that an email cannot really have those properties set until after it is sent.

It kind of looks like you are setting them in the email dialog when you are manual clicking those options when composing the email but the items are not really created until after the email is sent.

The hitch is that the handle to an email being composed is no longer valid after you send it. So you have a handle that you are using to add stuff like "To", "From", "Subject", "Body", etc. to an email being composed. Once that email is sent, that object basically ceases to exist. Then a new object is created once the email is sent which is then added to your database of emails.

It does not appear there is an easy way to go from the before handle to an after handle. From what I can tell you have to add a property to the before email to identify it later, then watch the sent items folder for an email to show up that has been branded for further processing at which point you add follow ups and task and such to it.

I don't like that process at all. Maybe there is a better way but in my research I only saw several versions of that technique as the way others have done it. (all in other scripting languages, mostly VBA)

Might be able to automate the actual menus on the email compose dialog but I don't like that solution either.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
emretoprak
Posts: 19
Joined: 14 Jun 2017, 07:56

Re: Outlook COM: Setting account to send from

01 Sep 2017, 03:21

Could you tell me how to use the AHK to display the value of outlook properties? I think it might be possible to include the reminder property before sending the email.

Thanks for taking your time for detailed explanations above. Really appreciate it.
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Outlook COM: Setting account to send from

01 Sep 2017, 12:06

emretoprak wrote:Could you tell me how to use the AHK to display the value of outlook properties? I think it might be possible to include the reminder property before sending the email.

Thanks for taking your time for detailed explanations above. Really appreciate it.
This code will let you see the "Subject" of an active open email. "Subject" can be changed to any property.

Code: Select all

F12::
   olEmail := ComObjActive("Outlook.Application").ActiveWindow.CurrentItem
	MsgBox % olEmail.Subject ; Change "Subject" to any property
return
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
emretoprak
Posts: 19
Joined: 14 Jun 2017, 07:56

Re: Outlook COM: Setting account to send from

06 Sep 2017, 07:23

Do you think this can be converted to AHK code?

Code: Select all

Public Sub SetCustomFlag()

Dim objMsg As Object

' GetCurrent Item function is athttp://slipstick.me/e8mio
Set objMsg = GetCurrentItem()

With objMsg

' due this week flag
    .MarkAsTask olMarkThisWeek
' sets a specific due date
    .TaskDueDate = Now + 3

    .FlagRequest = "Call " & objMsg.SenderName
    .ReminderSet = True
    .ReminderTime = Now + 2
    .Save
End With

Set objMsg = Nothing
End Sub
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Outlook COM: Setting account to send from

06 Sep 2017, 15:54

emretoprak wrote:Do you think this can be converted to AHK code?

Code: Select all

Public Sub SetCustomFlag()

Dim objMsg As Object

' GetCurrent Item function is athttp://slipstick.me/e8mio
Set objMsg = GetCurrentItem()

With objMsg

' due this week flag
    .MarkAsTask olMarkThisWeek
' sets a specific due date
    .TaskDueDate = Now + 3

    .FlagRequest = "Call " & objMsg.SenderName
    .ReminderSet = True
    .ReminderTime = Now + 2
    .Save
End With

Set objMsg = Nothing
End Sub
That does not look like functioning code as Now + 2 does not seem valid.

But sure something like that can be done in AHK, but it will not work for 'draft' emails before they are sent.

Code: Select all

F12::
	olEmail := ComObjActive("Outlook.Application").ActiveWindow.CurrentItem	; Expects an Email to be open
	olEmail.MarkAsTask(2) ; olMarkThisWeek := 2
	olEmail.TaskDueDate := DatePlusDays(3)
	olEmail.FlagRequest := "Call " olEmail.SenderName
	olEmail.ReminderSet := true
	olEmail.ReminderTime  := DatePlusDays(2)
	olEmail.Save
return

DatePlusDays(Days, Format := "MM/dd/yyyy", Date := "")
{
	if !Date
		Date := A_Now
	Date += Days, Days
	FormatTime, Date, %Date%, %Format%
	return Date
}
That code should work fine on sent or received emails.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
jomo86
Posts: 10
Joined: 04 Oct 2017, 14:38
Contact:

Re: Outlook COM: Setting account to send from

12 Oct 2017, 09:16

FanaticGuru, this is awesome!

How did you find these events, and how can I find more of them? Since Outlook 2016 disabled launching a script/exe internally via a mail "Rule", I'm looking for a way to trigger a script (via ahk) by monitoring Outlook events.
For instance, to trigger a scripted action when an e-mail comes with a specific SUBJECT or even sender.

Thanks!

FanaticGuru wrote:
Below are several event triggers that can be used related to new emails in Outlook:

This is the most basic. It triggers the procedure anytime a new email is received.

Code: Select all

olApp := ComObjActive("Outlook.Application")
ComObjConnect(olApp, "EventApp_")

EventApp_NewMail()
{
	MsgBox % NEW MAIL
}
It does not give you a handle to the new email though and it can be problematic to figure out what email was received if several are received in the same download.

This is better. The procedure is passed a list of IDs for all emails downloaded in the last batch.

Code: Select all

 ;~ NEW MAIL USING EXCHANGE LIST
global olApp := ComObjActive("Outlook.Application")
ComObjConnect(olApp, "EventApp_")

EventApp_NewMailEx(IDs)
{
	IDs := StrSplit(IDs, ",")
	for index, ID in IDs
		MsgBox % olApp.Session.GetItemFromID(ID).Subject
}
Another approach is to set an event trigger for when a new item is added to a folder.

Code: Select all

olApp := ComObjActive("Outlook.Application")
olNameSpace := olApp.GetNamespace("MAPI")
olFolderItems := olNameSpace.Folders("Account Display Name").Folders("Inbox").Folders("Important Stuff").Items

ComObjConnect(olFolderItems, "EventFolderItems_")

EventFolderItems_ItemAdd(olItem)
{
	MsgBox % olItem.Subject
}
This will trigger everytime a new item is added to the Important Stuff subfolder of the Inbox for a specific account.

Connecting to an objects events is very similar to the way hotkeys work. Hotkeys are events that trigger a procedure. In all of these examples the "Event" procedure is trigger anytime the event occurs in the object connected.

FG
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Outlook COM: Setting account to send from

12 Oct 2017, 15:19

jomo86 wrote:FanaticGuru, this is awesome!

How did you find these events, and how can I find more of them? Since Outlook 2016 disabled launching a script/exe internally via a mail "Rule", I'm looking for a way to trigger a script (via ahk) by monitoring Outlook events.
For instance, to trigger a scripted action when an e-mail comes with a specific SUBJECT or even sender.

Thanks!
I found these events pretty much the way I find out how to do all coding, googling.
Google "msdn outlook events"
MSDN is Microsoft's Developer's Network. Which has a wealth of information on how to do things with Microsoft products.

There are all kinds of events on different levels. Application events, mailitem events, explorer events, folder events, etc. There are many, many individual events that can be monitored.

For your specific need I would use NewMailEx which gets a list every time emails are downloaded. Then just loop through that list of emails and look at any property of the email and decide what to do with it. Through MSDN you can find all the properties of an email. There is a property that can be accessed for pretty much everything there is about an email.

My example already has it listing the Subject of all received emails. It should be pretty easy to add an If-Then to do something if the Subject is or contains a certain string. The sky is the limit really. Auto-replies with requested attachments, forward, create contracts, reminders, add stuff to calendars, etc. Especially if you get very structured emails (like they are generated by a computer), you can create structured things to do with those emails. For example say you get a ton of emails from Amazon orders, you could have all that notification, shipping, billing, order information automatically logged to an Excel sheet to track department expenditures and generate reports.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
User avatar
derz00
Posts: 497
Joined: 02 Feb 2016, 17:54
Location: Middle of the round cube
Contact:

Re: Outlook COM: Setting account to send from

12 Oct 2017, 18:24

jomo86 wrote:FanaticGuru, this is awesome!

How did you find these events, and how can I find more of them?
Hey, there's a webinar coming up about this, FYI... https://autohotkey.com/boards/viewtopic ... 76#p175676
try it and see
...
jomo86
Posts: 10
Joined: 04 Oct 2017, 14:38
Contact:

Re: Outlook COM: Setting account to send from

20 Oct 2017, 13:28

FanaticGuru wrote: I found these events pretty much the way I find out how to do all coding, googling.
Google "msdn outlook events"
MSDN is Microsoft's Developer's Network. Which has a wealth of information on how to do things with Microsoft products.

There are all kinds of events on different levels. Application events, mailitem events, explorer events, folder events, etc. There are many, many individual events that can be monitored.

For your specific need I would use NewMailEx which gets a list every time emails are downloaded. Then just loop through that list of emails and look at any property of the email and decide what to do with it. Through MSDN you can find all the properties of an email. There is a property that can be accessed for pretty much everything there is about an email.

My example already has it listing the Subject of all received emails. It should be pretty easy to add an If-Then to do something if the Subject is or contains a certain string. The sky is the limit really. Auto-replies with requested attachments, forward, create contracts, reminders, add stuff to calendars, etc. Especially if you get very structured emails (like they are generated by a computer), you can create structured things to do with those emails. For example say you get a ton of emails from Amazon orders, you could have all that notification, shipping, billing, order information automatically logged to an Excel sheet to track department expenditures and generate reports.

FG
Thanks! I found some MSDN resources once I knew what it was called. So... I've done a few lightweight things with AHK, but I'm a noob with coding.

I'm trying to figure out how to turn these properties into a code. Can you help start me in the right direction?

For the sake of an experiment, I'm trying to set the trigger as a New e-mail arriving into Outlook. When the new e-mail comes, I want AHK to make regular old pop-up MsgBox. If I can the general format right, then I can make AHK do whatever I want later.

How should I format this?

Code: Select all

olApp := ComObjActive("Outlook.Application")
ComObjConnect(olApp, "EventApp_")

if 
EventApp_NewMailEx()
{
MsgBox You have a new e-mail
}


Thanks!
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Outlook COM: Setting account to send from

20 Oct 2017, 13:50

jomo86 wrote:How should I format this?

Code: Select all

olApp := ComObjActive("Outlook.Application")
ComObjConnect(olApp, "EventApp_")

if 
EventApp_NewMailEx()
{
MsgBox You have a new e-mail
}


Thanks!

Code: Select all

global olApp := ComObjActive("Outlook.Application")
ComObjConnect(olApp, "EventApp_")

EventApp_NewMailEx(IDs)
{
	MsgBox You have a new e-mail
}
No need for an If. Events by their nature only trigger "if" the event occurs.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
jomo86
Posts: 10
Joined: 04 Oct 2017, 14:38
Contact:

Re: Outlook COM: Setting account to send from

20 Oct 2017, 15:22

FanaticGuru wrote:

Code: Select all

global olApp := ComObjActive("Outlook.Application")
ComObjConnect(olApp, "EventApp_")

EventApp_NewMailEx(IDs)
{
	MsgBox You have a new e-mail
}
No need for an If. Events by their nature only trigger "if" the event occurs.

FG

Thanks for your help.
This event (getting a new e-mail) is not triggering anything for me. Is that the entire AHK file, or is there something else that needs to be present in the script for this to work?
At this point, I'm not limiting the e-mail to certain properties (subject, etc). I'm just trying to get ANY e-mail to trigger anything. I also tried setting the event to send #m (to minimize everything) when getting an e-mail--just as a test. I can make a hotkey work easily, but I don't know how to make this COM event into a trigger.

Can you point me in the right direction? I am really stuck getting this off the ground. I haven't found anything online about these events being used as triggers---it's usually the other way around.
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Outlook COM: Setting account to send from

20 Oct 2017, 17:35

jomo86 wrote:
FanaticGuru wrote:

Code: Select all

global olApp := ComObjActive("Outlook.Application")
ComObjConnect(olApp, "EventApp_")

EventApp_NewMailEx(IDs)
{
	MsgBox You have a new e-mail
}
No need for an If. Events by their nature only trigger "if" the event occurs.

FG

Thanks for your help.
This event (getting a new e-mail) is not triggering anything for me. Is that the entire AHK file, or is there something else that needs to be present in the script for this to work?
That script snippet will run and then terminate. There needs to be something in the script that keeps it running like a hotkey definition. Or you can simply put Persistent at the top.

This should work as a complete, stand-alone script.

Code: Select all

#Persistent

global olApp := ComObjActive("Outlook.Application")
ComObjConnect(olApp, "EventApp_")

EventApp_NewMailEx(IDs)
{
	MsgBox You have a new e-mail
}
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
jomo86
Posts: 10
Joined: 04 Oct 2017, 14:38
Contact:

Re: Outlook COM: Setting account to send from

23 Oct 2017, 07:55

FanaticGuru wrote:
jomo86 wrote:
FanaticGuru wrote:
That script snippet will run and then terminate. There needs to be something in the script that keeps it running like a hotkey definition. Or you can simply put Persistent at the top.

This should work as a complete, stand-alone script.

Code: Select all

#Persistent

global olApp := ComObjActive("Outlook.Application")
ComObjConnect(olApp, "EventApp_")

EventApp_NewMailEx(IDs)
{
	MsgBox You have a new e-mail
}
FG

Yes! That's just what I needed. I really appreciate your help.

And thanks for the explanation about running and terminating. I had seen the #persistent tag before, but didn't fully understand why it was needed, so that puts it all together for me. Thanks for taking the time to help!

I have another part I need to figure out. I really wanted to figure this out using google, like you mentioned, but everything I'm seeing is using AHK to create an Outlook event, not trigger. I've been playing around with the parameters, but with no luck. How can I specify only e-mail with a certain subject to be a trigger? For instance, if the subject is "test123", it will trigger an action, but all other e-mails will not trigger anything.

I see your earlier comment will show details about the subject within the MsgBox, but I don't see how to limit the trigger by that property. Can you help me out? I have been doing hotkeys for a long time, but I am just now getting started into learning some deeper coding.
Thank you!
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Outlook COM: Setting account to send from

23 Oct 2017, 13:05

jomo86 wrote:How can I specify only e-mail with a certain subject to be a trigger? For instance, if the subject is "test123", it will trigger an action, but all other e-mails will not trigger anything.
You don't try to limit what will trigger the event, you limit what you do once an event is triggered.

Code: Select all

#Persistent	; Script must continue to run to work

global olApp := ComObjActive("Outlook.Application")
ComObjConnect(olApp, "EventApp_")

EventApp_NewMailEx(IDs)
{
	IDs := StrSplit(IDs, ",")
	for index, ID in IDs
	{
		olMailItem := olApp.Session.GetItemFromID(ID)
		if (olMailItem.Subject = "test123")
			MsgBox % olMailItem.Subject " : received from > " olMailItem.Sender
	}
}
In this script downloading emails will trigger the event. When the event triggers the function is passed the IDs of all emails downloaded in this batch. The script then loops through those emails (it could be just one) and if any of them have the subject it is looking for then it does something.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
jomo86
Posts: 10
Joined: 04 Oct 2017, 14:38
Contact:

Re: Outlook COM: Setting account to send from

23 Oct 2017, 13:36

FanaticGuru wrote:
jomo86 wrote:How can I specify only e-mail with a certain subject to be a trigger? For instance, if the subject is "test123", it will trigger an action, but all other e-mails will not trigger anything.
You don't try to limit what will trigger the event, you limit what you do once an event is triggered.
FG
Brilliant---of course. And thanks for the explanation behind it as well. You make it look easy.

I've been studying a lot of the MSDN properties/events over the last few days.
I just read this morning on this MSDN link https://msdn.microsoft.com/en-us/librar ... ailex.aspx
that processing IDs for NewMailEx should be used with caution because it could hinder Outlook performance. I could see how that would happen if EVERY new e-mail has to go through the processing.

Do you think it would be better for me to trigger using a different event?
I was thinking I could use Outlook to create a "rule" and then use the rule event as an AHK trigger.
Do you think that would be better, or do you think NewMailEx will be fine?

Thanks for everything. I'm gonna pick apart all the stuff you've posted here and try to figure out how to do even more.
Thanks again!
User avatar
derz00
Posts: 497
Joined: 02 Feb 2016, 17:54
Location: Middle of the round cube
Contact:

Re: Outlook COM: Setting account to send from

23 Oct 2017, 14:11

jomo86 wrote: Thanks for everything. I'm gonna pick apart all the stuff you've posted here and try to figure out how to do even more.
Thanks again!
Same here.

The OP (enjoying this thread)
try it and see
...
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Outlook COM: Setting account to send from

23 Oct 2017, 14:12

jomo86 wrote: I've been studying a lot of the MSDN properties/events over the last few days.
I just read this morning on this MSDN link https://msdn.microsoft.com/en-us/librar ... ailex.aspx
that processing IDs for NewMailEx should be used with caution because it could hinder Outlook performance. I could see how that would happen if EVERY new e-mail has to go through the processing.

Do you think it would be better for me to trigger using a different event?
I was thinking I could use Outlook to create a "rule" and then use the rule event as an AHK trigger.
Do you think that would be better, or do you think NewMailEx will be fine?
A typical user even a work type user should have no problems with checking every email. A thousand emails a day would be nothing.

Now on the other hand if you are doing something very time consuming with each batch of downloaded emails, that could be a problem. Like on the function loop you are manual composing replies to certain emails that takes 10 minutes and then Outlook downloads another batch of mails while you are still in that first function loop, then I am not sure what would happen. Or it is just sitting in mid loop with a MsgBox displayed which stops processing of the loop.

Edit: Just on a quick test. Outlook is not going to do anything else while sitting at that MsgBox in the Event. So until you finish that Event loop and pass control back, Outlook is basically paused. So not a good idea to do things that are going to basically stop the AHK thread like a MsgBox. If you really do want a notification or something like that stays displayed, better to do a Gui that gets displayed but lets the thread continue processing. No harm is going to be done by showing a MsgBox for testing and such but be aware that Outlook is effectively paused while that MsgBox is displayed. On the plus side you can take as long as you want in the Event handling and no craziness should happen just Outlook is paused.

If you are averaging 1 email a minute and moving it to a specific folder, that is pretty much nothing as far as your computer is concerned.

If it was a concern or you wanted things done in a different order than you could setup an event that fires anytime an email is added to a specific folder. Like even your inbox.

With the NewMailEx, that fires before any normal Outlook rules are applied. All emails are examined, even ones that a rule is going to send to the Junk folder. Watching a folder would trigger after any normal Outlook rules are applied.

Example of watching a folder for items added.

Code: Select all

#Persistent
olApp := ComObjActive("Outlook.Application")
olNameSpace := olApp.GetNamespace("MAPI")
olFolderItems := olNameSpace.Folders("[email protected]").Folders("Inbox").Folders("Stuff").Items

ComObjConnect(olFolderItems, "EventFolderItems_")

EventFolderItems_ItemAdd(olItem)
{
	MsgBox % olItem.Subject
}
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
jomo86
Posts: 10
Joined: 04 Oct 2017, 14:38
Contact:

Re: Outlook COM: Setting account to send from

24 Oct 2017, 06:49

derz00 wrote: Same here.

The OP (enjoying this thread)
Haha. Thanks for hosting my learning session, derz00!


FanaticGuru wrote: A typical user even a work type user should have no problems with checking every email. A thousand emails a day would be nothing.

Now on the other hand if you are doing something very time consuming with each batch of downloaded emails, that could be a problem. Like on the function loop you are manual composing replies to certain emails that takes 10 minutes and then Outlook downloads another batch of mails while you are still in that first function loop, then I am not sure what would happen. Or it is just sitting in mid loop with a MsgBox displayed which stops processing of the loop.

Edit: Just on a quick test. Outlook is not going to do anything else while sitting at that MsgBox in the Event. So until you finish that Event loop and pass control back, Outlook is basically paused. So not a good idea to do things that are going to basically stop the AHK thread like a MsgBox. If you really do want a notification or something like that stays displayed, better to do a Gui that gets displayed but lets the thread continue processing. No harm is going to be done by showing a MsgBox for testing and such but be aware that Outlook is effectively paused while that MsgBox is displayed. On the plus side you can take as long as you want in the Event handling and no craziness should happen just Outlook is paused.

If you are averaging 1 email a minute and moving it to a specific folder, that is pretty much nothing as far as your computer is concerned.

If it was a concern or you wanted things done in a different order than you could setup an event that fires anytime an email is added to a specific folder. Like even your inbox.

With the NewMailEx, that fires before any normal Outlook rules are applied. All emails are examined, even ones that a rule is going to send to the Junk folder. Watching a folder would trigger after any normal Outlook rules are applied.

Example of watching a folder for items added.

Code: Select all

#Persistent
olApp := ComObjActive("Outlook.Application")
olNameSpace := olApp.GetNamespace("MAPI")
olFolderItems := olNameSpace.Folders("[email protected]").Folders("Inbox").Folders("Stuff").Items

ComObjConnect(olFolderItems, "EventFolderItems_")

EventFolderItems_ItemAdd(olItem)
{
	MsgBox % olItem.Subject
}
FG
Perfect. I won't be doing any major processing with the e-mails (not even moving them to a new folder), so I think it'll be ok.

I did notice the MsgBox locks up Outlook. Thanks for the warning! The "MsgBox" was purely for testing.

The project is that I want to make an alert that can't be missed...when certain e-mails come. My plan was to make AHK launch an HTML page or something as a big visual alert. But now that you mention the GUI, I'm playing around with that a bit. Thanks for the suggestion!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, Google [Bot], ShatterCoder and 132 guests