1
votes

I have a third party piece of software that sends email through Outlook. It allows us to specify a "reply to" email address, but not a "from" email address. I'm trying to write something in VBA that notices when a message comes from that third party software and uses the "reply to" address as the "from" address before it sends the email. I'm having trouble getting any events to trigger when I send email with the third party software.

If I use

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
  MsgBox "Test"
End Sub

it triggers the message box when I send an email through Outlook, but not when the third party software does. Is there another event I should be looking at instead? I'm looking at Application events or MailItem events (http://msdn.microsoft.com/en-us/library/office/dn320237(v=office.15).aspx) and nothing but the Send events seem at all appropriate. I tried the sample code for the item Send event

Public WithEvents myItem As Outlook.MailItem 



Sub SendMyMail() 

 Set myItem = Outlook.CreateItem(olMailItem) 

 myItem.To = "Dan Wilson" 

 myItem.Subject = "Data files information" 

 myItem.Send 

End Sub 



Private Sub myItem_Send(Cancel As Boolean) 

 myItem.ExpiryTime = #2/2/2003 4:00:00 PM# 

End Sub

but it doesn't trigger even when I send an email through Outlook. I did try restarting Outlook before testing that out.

This question looks promising: How do I trigger a macro to run after a new mail is received in Outlook? but it involves setting an event listener to the Inbox. I've heard that there's a way to change settings somehow in a way that prevents the third party messages from being automatically sent, and when that happens they get stuck in Outlook's Drafts folder. How would I go about putting an event listener on the Drafts folder instead of the Inbox?

1
Interesting question. Any chance you can specify what this third party is?RubberDuck
It's Microsoft Dynamics GP.serme

1 Answers

1
votes

Application.ItemSend event is only fired if a message is sent through the Outlook Object Model. If the other app uses Extended MAPI, no event fires.