CDO generated message stuck in Outbox

  • Thread starter Thread starter Upul Samaranayake
  • Start date Start date
U

Upul Samaranayake

I am trying to use the CDO code below (based on MSDN) to send a mail
message. The code is run from within 'ThisOutlookSession'.

The problem is that the message sits in the Outbox.. does not get picked up
and delivered by Exchange. Subsequently, if I create and send a message
interactively using Outlook, then both messages get delivered immediately.

Looks like I need to trigger something at the end of this code. Not quite
sure what. Any ideas?

TIA

-----

Sub test()

Dim objSession As New MAPI.Session
objSession.Logon , , False, False
Dim objMessage As MAPI.Message

Set objMessage = objSession.Outbox.Messages.Add
objMessage.Subject = "Sample Message"
objMessage.Text = "This is some sample message text."

' create the recipient
Set objOneRecip = objMessage.Recipients.Add
objOneRecip.Name = "Fulano DeTal"
'objOneRecip.Type = CdoTo
objOneRecip.Resolve

' send the message and log off
objMessage.Update
objMessage.Send False, False
Set objMessage = Nothing
objSession.DeliverNow
objSession.Logoff

End Sub
 
Back
Top