Redemption emails to draft folder

S

simonkue

I have a VB6 pgm that used to generate outlook e-mails correctly prior to
v2002. Now I need Redemption. I can generate the e-mail but it goes to the
drafts folder and not directly to the Outbox. I can copy from Draft to Outbox
but it is not ready to be sent and needs to be individually entered and sent.
I should be able to generate e-mail directly to the Outbox. What am I doing
wrong?
Using Win2k and XP, Outlook 2k and 2002 - same results.
The following code is a routine called for each e-mail so that there is only
1 To and no cc or bcc per e-mail.

Function CreateMail(xsRecip As Variant, xsSubject As String, xsMsg As
String, _
Optional xsAttachments As String) As Boolean

' Create new e-mail

Dim xvRecip As Variant
Dim xvAttach As Variant
Dim xbResolveOK As Boolean
Dim xnLen As Integer

Dim oMailItem As Object
Dim oMail As Object

Dim myNameSpace As NameSpace
Dim myFolder As Object

Dim SafeItem, oItem

On Error GoTo CreateMail_Err

' Get the message text. If xsMsg=Clipboard, then that is where the text is
If xsMsg = "Clipboard" Then
xsMsg = Clipboard.GetText
End If

xnLen = Len(xsMsg) + 1

Set Application = CreateObject("Outlook.Application")
Set myNameSpace = Application.GetNamespace("MAPI")
myNameSpace.Logon
Set myFolder = myNameSpace.GetDefaultFolder(4) 'olFolderOutbox

Set SafeItem = CreateObject("Redemption.SafeMailItem")
Set oItem = Application.CreateItem(olMailItem)
SafeItem.Item = oItem

With SafeItem
.Item = oItem
.Recipients.Add xsRecip
xbResolveOK = .Recipients.ResolveAll

' Note that the attachment must have the full file path. File name alone
isn't good enough!

If Not IsMissing(xsAttachments) And xsAttachments <> "" Then
.Attachments.Add xsAttachments, olByValue, xnLen, "Enclosed file"
End If
.Subject = xsSubject
.Body = xsMsg
If xbResolveOK Then
On Error GoTo 0
.Save
.ExpiryTime = .CreationTime
' .Send
.CopyTo myFolder
Else
MsgBox "Unable to resolve recipient. Please check " & xsRecip
.Display
End If
End With

CreateMail = True

'Set oMailItem = Nothing
'Set orSafeMailItem = Nothing
'Set xgolApp = Nothing
'
CreateMail_End:
Exit Function

CreateMail_Err:
CreateMail = False
Resume CreateMail_End
End Function
 
K

Ken Slovak - [MVP - Outlook]

That's what always happens, don't worry about it. The mail item doesn't have
to be in Outbox to go out. Just call Send on the item and then if you want
it out immediately either call DeliverNow or use code to click the
Send/Receive or Send/Receive All menu commands. There's a sample for that in
the Redemption FAQ.
 
S

simonkue

Ken, Thanks for your answer. I've tested this and this part is fine.
Has it always been the case that e-mails can be sent from "anywhere" in
Outlook? I assumed that they had to be in the Outbox to be picked up.
 
K

Ken Slovak - [MVP - Outlook]

Outlook places them in Outbox, Redemption and some other API's place them in
Drafts and they move through Outbox so quickly you don't see them <shrug>.
It doesn't prevent things from working correctly.
 
D

Dmitry Streblechenko

Actually Redemption does not even try to move the message since doing so
will result in a ghost message. And by default Outlook creates new messages
in the Drafts folder.
You can explicitly move the item *before* using Redemption:

Set oItem = Application.CreateItem(olMailItem)
set oItem = oItem.Move(myFolder)

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
S

Sue Mosher [MVP-Outlook]

So, what is it with moving items out of Drafts? I've heard of other people encountering these "ghost" messages when they try to do that.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
D

Dmitry Streblechenko

That happens if you use the old instance of the mesage that was supposed to
be immediately released:

OldMessage.Move(SomeFolder)
OldMessage.Whatever
OldMessage.Save

Boom! You got a ghost message in the old parent folder. Don't know if that
happens 100% of the time, but it certainly does happen. The right way to do
that is

set NewMessage = OldMessage.Move(SomeFolder)
NewMessage.Whatever
NewMessage.Save

And Redemption cannot do this silently under the covers because it has no
way of replacing the reference to the old message in the calling code. The
caller must do that explicitly first.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

So, what is it with moving items out of Drafts? I've heard of other people
encountering these "ghost" messages when they try to do that.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top