outlook redemption send problems/question

  • Thread starter George Sambataro
  • Start date
G

George Sambataro

I am new to redemption object programming and while I have made progress, I
have a few problems/questions that hopefully someone can help out with.

I am testing on Outlook XP and I put together (with the help of info on the
internet) the attached code which is designed to send an email message.

When outlook is open on the desktop, the message only leaves the drafts
folder when the btn.execute is executed. The utils.delivernow does not seem
to work.

My main question is this.. Is this code supposed to work, and actually send
an email, when outlook is not running on the desktop?

When outlook is not running, I get a error 91,"object variable or with block
variable not set" on
Set btn = ol.ActiveExplorer.CommandBars.FindControl(1, 5488). I guess this
makes sense if outlook is not running. When I do open outlook I see that my
message is in the drafts folder. If it is supposed to be sent, when outlook
is not running, how can I make this happen?

Thanks for any help.

George


SendMail "test subject 33", "body of message2", "(e-mail address removed)", "", "",
""


Public Function SendMail(sSubj, sBody, sRecip, sRecipCc, sRecipBcc, sAttach)
Dim ol As Object ' added
Dim ns As Object
Dim newMail As Object
Dim SafeMail As Object
Dim btn As Object
Dim utils As Object

'Used to start Outlook
Set ol = CreateObject("Outlook.Application")

'Return a reference to the MAPI layer
Set ns = ol.GetNamespace("MAPI")
ns.Logon 'Added for Redemption

'Create a new mail message item
Set newMail = ol.CreateItem(0)
Set SafeMail = CreateObject("Redemption.SafeMailItem") '
SafeMail.Item = newMail 'Added for Redemption

With SafeMail
'Add the subject of the mail message
.Subject = (sSubj)
'Create some body text
.Body = (sBody)
'Do not save to Sent Items
.DeleteAfterSubmit = True

'Add a "To" recipient(optional)
If Len(sRecip) > 0 Then
With .Recipients.Add(sRecip)
.Type = 1
End With
End If

'Add a "Cc" recipient(optional)
If Len(sRecipCc) > 0 Then
With .Recipients.Add(sRecipCc)
.Type = 2
End With
End If

'Add a "Bcc" recipient(optional)
If Len(sRecipBcc) > 0 Then
With .Recipients.Add(sRecipBcc)
.Type = 3
End With
End If

'Attach a file as a link with an icon(optional)
If Len(sAttach) > 0 Then
With .Attachments.Add(sAttach)
End With
End If
End With

' send the email message

SafeMail.Recipients.ResolveAll

SafeMail.Send

' to force send
Set utils = CreateObject("Redemption.MAPIUtils")
utils.DeliverNow
' another way to force send
Set btn = ol.ActiveExplorer.CommandBars.FindControl(1, 5488)
btn.Execute


'Release memory
Set ol = Nothing
Set ns = Nothing
Set newMail = Nothing
Set btn = Nothing
Set utils = Nothing

End Function
 
K

Ken Slovak - [MVP - Outlook]

Outlook with no UI has no Explorers. Explorers are the folder views
you see in Outlook. So you can't access any buttons that would be
displayed in an Explorer unless an Explorer is present. You would need
to add an Explorer to the Explorers collection and use one of the
OlFolderDisplayMode constants in the optional DisplayMode argument
when you call the Add method of the Explorers collection.
 
G

George Sambataro

" You would need to add an Explorer to the Explorers collection and use one
of the
OlFolderDisplayMode constants in the optional DisplayMode argument
when you call the Add method of the Explorers collection."

You are definately above my head :) What would this do? How can I learn
more?

Is this the only way to make sure a message gets sent?

Thanks,

George
 
K

Ken Slovak - [MVP - Outlook]

An Explorer is what is opened when you display an Outlook folder. If
Outlook is started with no user interface there are no Explorers so
your call to ActiveExplorer will fail and you won't be able to execute
the button in the Explorer that you want to execute.

Dim oExpl As Outlook.Explorer

Set oExpl = ol.Explorers.Add(ns.GetDefaultFolder(olFolderInbox), _
olFolderDisplayNormal)

That would display an Explorer and then you could execute your button.

I usually just call the Send method of the SafeMailItem and then call
MAPIUtils.DeliverNow. However that can fail in Outlook 2002 when no
Exchange account is there because of limitations in the MAPI Spooler
in Outlook 2002. In that case you must find and execute the button as
you were doing.

When in doubt about something check in the Object Browser, it lists
the properties, methods and events each Outlook object exposes and the
help for those often shows code samples of how to use them.
 
G

George Sambataro

Thanks for your help AGAIN Ken.. :)

AS they say... A little knowledge is dangerous... I put together the
following logic using various sources.. It is meant to start Outlook it if
is not started yet.

Dim application, ns, ol
Set ol = CreateObject("Outlook.Application")
If ol.Explorers.Count = 0 Then
Set ns = ol.GetNamespace("MAPI")
ns.Logon
Dim oExpl As Outlook.Explorer
Set oExpl = ol.Explorers.Add(ns.GetDefaultFolder(olFolderInbox),
olFolderDisplayNormal)
End If


It does start an outlook.exe process (regardless if one is running or not)
but the button command still does not work.

Does this code make sense? Is it close?

Thanks,

George
 
K

Ken Slovak - [MVP - Outlook]

If you step the code are you getting a valid Explorer object when you
use ActiveExplorer? Do you get a valid CommandBarButton object? What
errors are you getting now?
 

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