Hello all,

I just have a problem automating Outlook (as if you could not have guessed that ). I've set up an Excel Workbook which will extract some data and then send it using MAPISendMail (can't use Outlook Objects because some users still have MSMail running ).

The basic problem is, that the sent mails land in the Outbox, but since my programs logs out from MAPI right after creating the mail, the mail lies there until the mail client is started next time (which can be some days later, best was 3 months ( !!), some people just don't like eMail at all).

Is there a way to force all messages to be sent before allowing my program to log out?

Here's part of my code handling the sending:

[VBA]
Dim mRecip(0) As MapiRecip, mFile(0) As MapiFile, mMail As MAPIMessage, lSess&, lRet&

[...snip Just setting up the mail, attachments etc. here...]

lRet = MAPILogon(0, "", "", MAPI_LOGON_UI, 0, lSess)
If lRet <> SUCCESS_SUCCESS Then
strError = "Fehler beim Einloggen in Mailsoftware. (" & CStr(lRet) & ")"
GoTo ErrorHandler
End If

lRet = MAPISendMail(lSess, 0, mMail, mRecip, mFile, MAPI_NODIALOG, 0)
If lRet <> SUCCESS_SUCCESS And lRet <> MAPI_USER_ABORT Then
If lRet = 14 Then
strError = "Zieladresse kann nicht gefunden werden, stellen Sie sicher, dass das globale Adressbuch zur Verf?gung steht und die Adresse g?ltig ist."
Else
strError = "Fehler beim Senden: " & CStr(lRet)
End If
GoTo ErrorHandler
End If

lRet = MAPILogoff(lSess, 0, 0, 0)
SendIt = True
Exit Function
ErrorHandler:
If strError = "" Then strError = Err.Description
Call MsgBox(strError, vbExclamation, "Fehler beim Senden")
End Function
[/VBA]