PDA

View Full Version : [SOLVED:] Send mail (outlook) based on template stored in Access



denbob
02-09-2022, 05:12 AM
Hi there,
I want to send a mail , using a template I stored in Access itself (WorkToDo.oft) . I have a small table "tbl_Sjablonen" in which I store my templates.
I know the code for creating a mail based on a template, stored on e.g. "c:\L01" but I want to store the template files in my Access database (only 2 to 3 templates) .
Can anyone show me the way?

Thx in advance !
Bob

arnelgp
02-09-2022, 08:01 AM
store the Template in an Attachment field.
Extract it when you need to use it.

denbob
02-10-2022, 06:13 AM
I have done that, it's a .otf (outlook template file) . But I want to create an email with that template file.
Normally, the code for doing this (at least the one I know) =>

NewMail = obApp.CreateItemFromTemplate("G:\Shared\test"[/COLOR])

(with NewMail defined as MailItem and obApp as Object). But in stead of the "G:\shared\test" I want to use the template file stored in my table (as attachment Field).

I could of course first extract the file (the *.otf) file to the disk and then create the new mail, and afterwards delete the file on disk.
But this seems to me to be a workaround.

In short the code would be something like : Set Newmail = obapp.createItemFromTemplate (...)
with ... something that refers directly to a record of my table with all my templates (tabel of records with name and attachmentfield, the file itself) .
This record has to be found before the creation of the mail of course, this is no problem.


It works with extraction to Cl\L01, but I want to shortcut the extraction and set newmail... ("C:\L01\templatemail.otf")

Thanks in advance for considering my question.
Bob

arnelgp
02-10-2022, 07:37 PM
upload your db or show your code.
basically, you create MailObject from your Template:

Set newMail= objOutlook.CreateItemFromTemplate("C:\L01\templatemail.otf")

denbob
03-08-2022, 03:14 AM
I save the template file in a folder on the computer ("C:\L01") and then I use it as template to create a mail.
This works, thx anyway for your advise.
(I was looking for a shorter way, but it works and that is the most important thing for my boss, so problem solved).