Redemption Send EMail fails

  • Thread starter Thread starter Peter Hibbs
  • Start date Start date
P

Peter Hibbs

I am using MS Access 2003 to send an email via Outlook 2003 using
Redemption to prevent the security messages on Windows XP. The basic
(cut down) code is shown below :-


Dim SafeItem, oItem
Dim Application As Outlook.Application


Set Application = CreateObject("Outlook.Application")
Set SafeItem = CreateObject("Redemption.SafeMailItem") Set
oItem = Application.CreateItem(0) SafeItem.Item = oItem
SafeItem.Subject = vSubject
SafeItem.To = vRecipients
SafeItem.Body = vBody

SafeItem.Send


The string variables vSubject, vRecipients and vBody obviously holds
the relevant text. I have also omitted some error checking code in the
interests of clarity.

The code is part of a MS Access application and works perfectly when
Outlook is running at the same time. If, however, Outlook is NOT
running the code fails at the SafeItem.Send command with an error
that just says 'The server threw an exception' and Outlook does not
close down properly, I have to forcibly close it with the Windows Task
Manager.

The Redemption.dll file is located in the C:\WINDOWS\System32 folder
and has been registered with RegSvr32.exe. A reference to the .dll
file has been enabled in Access.

Is there any way I can run this code without having to run Outlook
first?

Peter Hibbs.
 
You need to log in first:

Set Application = CreateObject("Outlook.Application")

set NS = Application.GetNamespace("MAPI")
NS.Logon

Set SafeItem = CreateObject("Redemption.SafeMailItem") Set
oItem = Application.CreateItem(0) SafeItem.Item = oItem
SafeItem.Subject = vSubject
SafeItem.To = vRecipients
SafeItem.Body = vBody

SafeItem.Send


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

Thank you. That works now although I had to declare NS as a Variant
first -

Dim NS

Is that correct or should it be declared as some other object type. I
notice also that when I open Outlook the sent email also appears in
the Drafts folder and disappears when I next check for emails. Is this
OK (I remember reading something about this on your Web site, I will
investigate further).

Anyway, thanks again for your help.

Peter Hibbs.
 
Either a generic Object or Outlook.Namespace woudl do.
Message submitted directly from teh Drafts folder is perfectly normal - a
message can be send from any folder, Outbox is simply an eye candy.
Redemption does nto move the message to the Outbox when you call Send of
purpose since that can create a ghost message. You can explicitly move the
message first before using Redemption:

Set Application = CreateObject("Outlook.Application")
set NS = Application.GetNamespace("MAPI")
NS.Logon
Set SafeItem = CreateObject("Redemption.SafeMailItem")
Set oItem = Application.CreateItem(0)

set oItem = oItem.Move(NS.GetDefaultFolder(6)) 'Outbox

SafeItem.Item = oItem
SafeItem.Subject = vSubject
SafeItem.To = vRecipients
SafeItem.Body = vBody

SafeItem.Send

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