Automate Send Email from MS Access

Hi all,

I have an MS Access db (I know… bad words here) which contains a piece of code to create an email and then send via the default MAPI client (DoCmd.SendObject if this helps). The MAPI client was Outlook Express, but needs to change to use Lotus Notes (hurrah! I hear at the back). And testing it, it works too. Almost.

Part of the code (DoCmd.SendObject) has a flag that specifies whether the email is displayed for editing or sent immediately. It is set for send immediately (and does so under Outlook Express client), but Lotus Notes client will not do this and instead displays it for editing. Are there any Notes/MS Access devs out there kind enough to point out a) whether this is just a stonewall incompatability between the MS Access code and Notes, or b) there is some setting in Notes that (as a non-Notes dev) I am not aware of and need to configure. If it’s the latter it would also be appreciated if you could tell me what this is… :wink:

Thanks in advance.

Geoff

Subject: Automate Send Email from MS Access

Hello,

Why don’t you try to pilot Lotus Notes client with OLE Automation ?

A+

Subject: RE: Automate Send Email from MS Access

Hi Pierre,

If no one comes back to me with an answer one way or the other then come Monday I’ll be re-writing the email output routine using CreateObject(“Notes.NotesSession”), etc!!!

In the meantime I was looking for an answer as to whether there was a quick way of keeping the same code OR whether the two applications just won’t talk to each other. Period.

Thanks,

Geoff

Subject: RE: Automate Send Email from MS Access

You’ll need to rewrite if you don’t want it to go straight to the UI – Notes may be the mail client, but it ain’t a MAPI client as such.

Just one thing, though – don’t use the Notes Automation Objects (“Notes.NotesSession”) if you can avoid it – and if you don’t want or need the UI, you can avoid it. Use the COM interface instead – it’s more stable and considerably faster. As a code reference, you’d choose Lotus Domino Objects. Rather than declaring everything as a Variant, you’d use proper data types:

Dim nSession As NotesSession

Dim dbDir As NotesDbDirectory

Dim mailDb As NotesDatabase

Dim mailDoc As NotesDocument

Dim body As NotesRichTextItem

nSesson = CreateObject(“Lotus.NotesSession”)

nSession.Initialize()

Note that launching a Notes client operation requires the user to be logged in to the client. If the client is not open at this point, he/she will be prompted for a password. If this operation is happening on a single machine, you can use a password string as an Initialize parameter to silently use Notes.

dbDir = nSession.GetDbDirectory(nSession.GetEnvironmentString(“MailServer”,True))

mailDb = dbDir.OpenMailDatabase

mailDoc = mailDb.CreateDocument

The biggest difference between the old stuff you’ll find on the Access boards and the code you’ll actually need is that you’ll need to use the full Object.Method(parameters) syntax:

With mailDoc

.AppendItemValue(“Form”,“Memo”)

.AppendItemValue(“SendTo”,<addressees As String, String Array or Variant>)

.AppendItemValue(“CopyTo”,)

.AppendItemValue(“BlindCopyTo”,)

.AppendItemValue(“Subject”,“Subject As String”)

End With

body = mailDoc.CreateRichTextItem(“Body”)

body.AppendText(“Message Text Goes Here”)

mailDoc.Send(False)

body = Nothing

mailDoc = Nothing

mailDb = Nothing