Frage

I have a .NET application which allows users to click a button that will launch a new pre-populated message in Outlook. This works great for the most part, with one minor exception. If the user does not have Outlook open when they send the message, then the message will go into their Outbox until they actually launch the main Outlook application. Only then does a Send/Receive ever seem to actually happen.

Here is the snippet of code I am using to create the MailItem:

Dim mailItem As Outlook.MailItem = Me.OutlookApplication.CreateItem(Outlook.OlItemType.olMailItem)
mailItem.To = "test@test.com"
mailItem.Subject = "Some Subject"
mailItem.HTMLBody = "Some Text"
mailItem.Display(False)

I hook into the ItemSend event for the Outlook.Application as well, so I am able to see that when the user clicks Send from the MailItem, Outlook successfully raises the event.

If Outlook is not running when the user launches the message, then a new OUTLOOK.EXE process is spawned. In either case, an icon will appear in the system tray signifying that Outlook is connected to an external application.

Is it possible for me to somehow trigger a Send/Receive using Interop, so I can ensure that the message will be sent without requiring the user to open Outlook separately?

War es hilfreich?

Lösung

Try to use Namespace.SendAndReceive

Keep in mind that message submission is asynchronous, so you need to keep Outlook.Application alive until Send/Receive finishes.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top