Redemption Send EMail

P

Peter Hibbs

With Outlook 2003 and Access 2003 I am using the following code to
send emails from an Access database using Outlook Redemption.

Dim SafeItem As Object, oItem As Object
Dim objApp As Object, NS As Object

'Create instance of Outlook Application
Set objApp = CreateObject("Outlook.Application")
Set NS = objApp.GetNamespace("MAPI")
NS.Logon

'Create an instance of Redemption.SafeMailItem
Set SafeItem = CreateObject("Redemption.SafeMailItem")
Set oItem = objApp.CreateItem(0)
SafeItem.Item = oItem
SafeItem.To = "email address here"
SafeItem.Subject = "email subject text"

SafeItem.BodyFormat = 2
SafeItem.HTMLBody = "email body text"

'Send email and close
SafeItem.Send
Set SafeItem = Nothing
Set oItem = Nothing
Set NS = Nothing
Set objApp = Nothing

I notice that the email ONLY gets sent if Outlook is actually running.
Is this correct and, if so, is there any way to send an email while
Outlook is NOT loaded?

Peter Hibbs.
 
M

Michael Bauer [MVP - Outlook]

If Outlook is set to send emails immediately, which usually means within the
next minute, you just need to wait until the mail is sent before you close
Outlook.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Sun, 30 Aug 2009 14:52:19 +0100 schrieb Peter Hibbs:
 
P

Peter Hibbs

Michael,

I was sort of under the impression that the Redemption code worked
independently of Outlook (although Outlook needs to be installed).
Having said that, I don't know why as there is no indication of that
on Dmitry's Web site, perhaps I read it somewhere.

Anyway, I was hoping that it would be possible to send an email from
within Access without having Outlook running but you appear to be
saying that that is not possible. I do have the 'Send immediately when
connected' flag set and the code works fine with Outlook running.

Oh well!!

Peter Hibbs.
 
K

Ken Slovak - [MVP - Outlook]

You can send without Outlook running, but you need to be using Exchange for
that to work. If you log into an Exchange mailbox you can do so without
running Outlook as long as you have the server-side MAPI installed. That
means no Office installed at all. Then you can send an item and Exchange
will take care of getting it out. I do that for some Windows services I've
written.

Other than that you do need an Outlook session running to actually have an
email go out.
 
P

Peter Hibbs

OK Ken, thanks for that.

I don't know anything about 'Exchange' but I will look into it. I
suspect it will be easier just to have Outlook running (it probably
will be anyway).

Peter Hibbs.
 
K

Ken Slovak - [MVP - Outlook]

Exchange is a mail server, if you're not familiar with it you're not using
it most likely. It's for corporations, not for home or private users.
 
P

Peter Hibbs

Dmitry,

Not sure I understand. Are you saying that if I add this code (from
your Web site) to my code that it will send the email without Outlook
loaded? If so, then I cannot get it to work, or perhaps I have
mis-read your FAQ #1.

"Note that the code above assumes that there is an active Explorer;
this will not be the case if you start Outlook programmatically (and
it was not previously started by a user) and do not display any
folders. In this case you can start a sync using the the
Namespace.SyncObjects collection."

set NS = Application.GetNamespace("MAPI")
NS.Logon
Set Sync = NS.SyncObjects.Item(1)
Sync.Start

Peter Hibbs.
 
M

Michael Bauer [MVP - Outlook]

That's what I wanted to tell you as well. Your code starts Outlook, but it
closes it as soon as the execution has been finished because the variables
go out of scope.

In principle a solution might look like this (asuming that Outlook isn't
running yet):

Private m_OL as Outlook.Application
Private m_Exp as Outlook.Explorer
Private m_Ns as Outlook.Namespace

Sub Start()
Dim F as Outlook.Mapifolder
Set m_OL = CreateObject("outlook.application")
Set m_Ns=m_OL.GetNamespace("mapi")
Set F=m_Ns.GetDefaultFolder(olFolderInbox)
Set m_Exp=m_OL.Explorers.Add(F, 0)
' now create/send the email
End Sub

' Use a timer to call this method, say, every minute
Sub CheckIfMailIsSent()
Dim F as Outlook.Mapifolder
Set F=m_Ns.GetDefaultFolder(olFolderOutbox)
If F.Items.Count=0 Then
' assuming the email is sent now
' disable your timer (!), then close Outlook
m_Exp.Close
Set m_Exp=Nothing
Set m_Ns=Nothing
m_OL.Quit
Set m_OL=Nothing
Endif
End sub

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Mon, 31 Aug 2009 22:01:04 +0100 schrieb Peter Hibbs:
 
P

Peter Hibbs

Michael,

I looked at your suggestion but I could not get it to work (probably
me) and I am not sure now if using Redemption will meet my
requirements on this project anyway.

I have done a bit more research and found some code called OstroSoft
SMTP Component by Igor Ostrovsky (OstroSoft). I have successfully got
the demo database program working and am now trying to integrate the
code into my own database.

Have you any comments about this code that I should know about?

Thanks for your help.

Peter Hibbs.
 

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