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.
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
-
"Peter Hibbs" <peter...@btinternet.com.NO_SPAM> wrote in message
news:g1kd059kdqsdufupl...@4ax.com...
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.
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
-
"Peter Hibbs" <peter...@btinternet.com.NO_SPAM> wrote in message
news:6cje05lb9tojqmkq0...@4ax.com...
Thanks very much, will try that.
Peter Hibbs.