In Outlook Web Add-In, I'm trying to intercept OnSend event which is triggered when sending an email.
I used this example in GitHub which is working fine.
If I include the word "attachment" in the email body and I click Send button, OnSend event is fired for the first time so I can do some processing to email's content. However, after a while, a pop-up modal window shows up with this message:
Attachment reminder
You may have forgotten to attach a file.
with Send and Don't send buttons. If click Send, OnSend event gets fired a second time. This time, It would be useless to repeat the same email processing. So, I'm looking for a way to find out that the second OnSend event is fired after an Attachment reminder.
Is there a way to distinguish between first and second OnSend events?
Thanks for your question, Mhd! This appears to be unintentional behavior, essentially a defect that we will look into fixing. ItemSend event should inter operate with forgotten attachment detection nicely, and should only be raised after the detection happened. In other words, the first event should not be called at all. Is it a problem if you do the processing twice until this issue is resolved?
Related
Okay, looks like someone has encountered this problem before, but I didn't see any further comments or solutions. See the Edit in the accepted answer to this question.
My situation is like this.
I am running Outlook 2013 under Win10 x64 with an Exchange email account. I sometimes run Outlook for several days to a week or more at a time without closing it.
I want to raise an event when a new item is added to the Sent Mail folder. This needs to occur after the Application ItemSend event because, let's say, I want to delete the message after it is sent, which you cannot do from within the ItemSend event handler.
So I have the following code:
Public WithEvents goSent As Outlook.Items
Private Sub Application_Startup()
'Establish the global object for the folder we want to monitor.
Set goSent = Session.GetDefaultFolder(olFolderSentMail).Items
End Sub
Private Sub goSent_ItemAdd(ByVal Item As Object)
'Do stuff here.
End Sub
Everything works beautifully for a day or longer, but eventually the ItemAdd event handler stops firing. If I enter the VBA editor and manually run Application_Startup, then it starts working again.
[Edit:] One other bit of information: The "built-in" events, like Application ItemSend, always seem to fire reliably no matter how long Outlook has been running.
[Edit 2:] This time, I let things go for a day after the event stopped firing. I opened the VBA editor and put a breakpoint in the Application ItemSend procedure. When it stopped, I queried the goSent object and found that (a) it still existed (rather than being Nothing), but (b) it had only the items in it that were there yesterday, presumably at the time it became "untethered" from the Sent Mail items collection. When I submitted a new Set statement in the Immediate window, it immediately began to work again.
[Edit 3:] I noticed that the MSDN documentation says to put event handlers for custom objects--like my ItemAdd event--in class modules. I have mine in ThisOutlookSession, but it was my understanding that ThisOutlookSession is a class module. Is there a problem with that?
Any idea why this would happen and what to do about it? I considered adding an event handler for Application ItemSend and just reassigning the goSent object every time that's fired, but it doesn't address the underlying problem.
[Edit 4:] For a while now, I've had a Set statement in the Application ItemSend handler, and that seems to have mostly taken care of things, even though it's a workaround, not really a solution. It appears to fail when I have delayed delivery on a sent item for an extended time, and I don't send any further messages in the meantime. Then the goSent object disconnects from the Sent Mail collection, and the message is actually sent from the Outbox after that point and before Application ItemSend fires again.
Thanks!
[Edit 5:] Unrelated to original issue: I discovered that my macros fail to accomplish what I want with an Exchange server that is in online mode (i.e., not cached mode) if I have messages in the Outbox with delayed delivery and Outlook is closed when the delivery time passes. In online mode, Exchange itself sends these messages and adds them to the Sent Mail folder on the server, so when Outlook reopens, the messages are already in the Sent Mail collection and no event fires. Which makes sense. See discussion here. Looks like I would need to add something to my Application_Startup macro to look for messages sent since Outlook last closed.
I had similar issue and never found a proper solution. What I did was I wrote a little batch script that closes and opens outlook app, then I set a task in task scheduler to run it every hour outside of my working hours. You can also do it easily in vbs.
I have an Outlook VBA form, which (on the initialize event) loads various data into menus.
This works in normal usage, however, if you right click, send to (mail recipient) on a file or Send > Email in Word, when you click the button to load the form, the form displays but nothing in any events trigger either on the form load, or on the various click events.
Can anyone offer an explanation of why and how to work around the issue?
You need to handle the NewInspector event of the Inspectors class.
Outlook inspectors shown using Simple MAPI or mailto link do not fire inspector events. This was done on purpose.
Which particular event are you using?
Hi im trying to send messages through intercom every time an event is sent. Let's say i have a feature in my product which is submitting intercom events every time the user clicks a certain tab. I would like to send a message on every occur of the event. I have already set an auto message in my intercom app, but i´m just able to send the message the first time the event occurs.
According to the interecom support team, auto-messaging is the currently the only way to do it. For now, they do not support advanced/customized triggers like "send the user a welcome message for the first 3 times when he clicks some link"
I am developing a add-in to perform some actions when the first click happens on the message box in outlook (2013 version). I want to capture the Outlook.MailItem.Recipients as soon as the first click happens on message body box.
Possible approach to do this (just did a quick test, seems to work for 2013):
Register to NewInspector event of the Application object:
Application.Inspectors.NewInspector += ....;
In the event handler, register to the following event:
var editor = newInspector.WordEditor as Word.Document;
editor.Application.WindowSelectionChange += ....;
The handler fires when the selection changes, which is also happening when the user clicks the window.
Please note that you must keep references to all objects in this sample, else the event registrations will get lost.
I'm writing an Outlook Addin Ribbon in VB.net and getting on with it rather well, however I've come to a point where I'm stuck.
When sending an item, I also need to save the file in the reading format which it would appear in the 'Sent Items'.
If have tried mailItem.SaveAs("path", olSaveAsType) but it only saves as a draft item. Whereby you can edit the text.
I tried to loop through the sent items in the 'sent items' folder after sending, however Outlook hangs whilst my code is executing, thus holding up the actual sending of the email.
Is there a way this can be done?
Any help, hints or tips would be appreciated!
Message submission is an asynchronous process. Set up the Items.ItemAdd event handler on the Sent Items folder (Namespace.GetDefaultFolder(olFolderSentMail)) and process the sent message in the ItemAdd event handler.