A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook - Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Template or Form?



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old March 18th 10, 01:01 AM posted to microsoft.public.outlook.program_forms
deko[_2_]
external usenet poster
 
Posts: 6
Default Template or Form?


I need to generate HTML email using Access 2007/Outlook 2007. I have
enough experience with VBA to gin up the code, but Outlook 2007 is
something of a mystery to me.

Here's what I've tried:

1. created an .oft template
2. attempted to insert text into the template like this

Code:
--------------------
Set olApp = GetObject(, "Outlook.Application")
Set olmi = olApp.CreateItemFromTemplate(strOftPath)
olmi.HTMLBody = "HTMLBODYtext here/BODY/HTML"
--------------------


Unfortunately, this overwrites all the nice logos and such I had put in
the template.

Should I be using a Outlook Template or Form?

I like the idea of using templates because they are discrete files that
(hopefully) users can administer if they want to change logos/colors,
etc.

Since I can store formatted Rich Text in an Access Memo field, I was
thinking I could just dump that into the .oft - or use bookmarks in the
.oft to insert predefined blocks of text, like a NameAddress block.

Can I do that with an .oft? Or should I use an Outlook form?

What are some good resources for programming .oft templates?


--
deko
http://forums.slipstick.com

Ads
  #2  
Old March 18th 10, 05:13 AM posted to microsoft.public.outlook.program_forms
deko[_2_]
external usenet poster
 
Posts: 6
Default Template or Form?


Has anyone had any luck with this?


Code:
--------------------
Public Function EmbeddedHTMLGraphicDemo()

'This technique by Outlook MVP Neo uses undocumented MAPI properties and CDO
'to add an embedded image file to a message and set the CID so that an
'HTMLBody property img tag can set that image as the source. In VBA or
'Visual Basic, you will need to add a reference to the CDO 1.21 library
'to use this procedure

'Reference Required:
'[Microsoft CDO 1.21 Library]
'C:\Windows\System32\CDO.DLL

' Outlook objects
Dim objApp As Outlook.Application
Dim l_Msg As MailItem
Dim colAttach As Outlook.Attachments
Dim l_Attach As Outlook.Attachment
Dim oSession As MAPI.Session
' CDO objects
Dim oMsg As MAPI.Message
Dim oAttachs As MAPI.Attachments
Dim oAttach As MAPI.Attachment
Dim colFields As MAPI.Fields
Dim oField As MAPI.Field

Dim strEntryID As String

' create new Outlook MailItem
Set objApp = CreateObject("Outlook.Application")
Set l_Msg = objApp.CreateItem(olMailItem)
' add graphic as attachment to Outlook message
' change path to graphic as needed
Set colAttach = l_Msg.Attachments
Set l_Attach = colAttach.Add("c:\test\graphic.jpg")
l_Msg.Close olSave
strEntryID = l_Msg.EntryID
Set l_Msg = Nothing
' *** POSITION CRITICAL *** you must dereference the
' attachment objects before changing their properties
' via CDO
Set colAttach = Nothing
Set l_Attach = Nothing

' initialize CDO session
On Error Resume Next
Set oSession = CreateObject("MAPI.Session")
oSession.Logon "", "", False, False

' get the message created earlier
Set oMsg = oSession.GetMessage(strEntryID)
' set properties of the attached graphic that make
' it embedded and give it an ID for use in an IMG tag
Set oAttachs = oMsg.Attachments
Set oAttach = oAttachs.Item(1)
Set colFields = oAttach.Fields
Set oField = colFields.Add(CdoPR_ATTACH_MIME_TAG, "image/jpeg")
Set oField = colFields.Add(&H3712001E, "myident")
oMsg.Fields.Add "{0820060000000000C000000000000046}0x8514", 11, True
oMsg.Update

' get the Outlook MailItem again
Set l_Msg = objApp.GetNamespace("MAPI").GetItemFromID(strEntry ID)
' add HTML content -- the IMG tag
l_Msg.HTMLBody = "IMG align=baseline border=0 hspace=0 src=cid:myident"
l_Msg.Close (olSave)
l_Msg.Display

' clean up objects
Set oField = Nothing
Set colFields = Nothing
Set oMsg = Nothing
oSession.Logoff
Set oSession = Nothing
Set objApp = Nothing
Set l_Msg = Nothing

End Function
--------------------


--
deko
http://forums.slipstick.com

  #3  
Old March 18th 10, 01:29 PM posted to microsoft.public.outlook.program_forms
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Template or Form?

www.outlookcode.com has lots of form code samples and information.

However I'm not sure that's what you need. You can create a blank new email
using CreateItem() and then just set the HTMLBody property to your formatted
HTML and that will work just fine. I do that all the time in my code.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"deko" deko.47zw2a@invalid wrote in message news:deko.47zw2a@invalid...

I need to generate HTML email using Access 2007/Outlook 2007. I have
enough experience with VBA to gin up the code, but Outlook 2007 is
something of a mystery to me.

Here's what I've tried:

1. created an .oft template
2. attempted to insert text into the template like this

Code:
--------------------
Set olApp = GetObject(, "Outlook.Application")
Set olmi = olApp.CreateItemFromTemplate(strOftPath)
olmi.HTMLBody = "HTMLBODYtext here/BODY/HTML"
--------------------


Unfortunately, this overwrites all the nice logos and such I had put in
the template.

Should I be using a Outlook Template or Form?

I like the idea of using templates because they are discrete files that
(hopefully) users can administer if they want to change logos/colors,
etc.

Since I can store formatted Rich Text in an Access Memo field, I was
thinking I could just dump that into the .oft - or use bookmarks in the
oft to insert predefined blocks of text, like a NameAddress block.

Can I do that with an .oft? Or should I use an Outlook form?

What are some good resources for programming .oft templates?


--
deko
http://forums.slipstick.com


  #4  
Old March 18th 10, 01:30 PM posted to microsoft.public.outlook.program_forms
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Template or Form?

What about it? What problem are you having, if any?

If you are having a problem indicate where and mention your Outlook version.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"deko" deko.4807my@invalid wrote in message news:deko.4807my@invalid...

Has anyone had any luck with this?


Code:
--------------------
Public Function EmbeddedHTMLGraphicDemo()

'This technique by Outlook MVP Neo uses undocumented MAPI properties and
CDO
'to add an embedded image file to a message and set the CID so that an
'HTMLBody property img tag can set that image as the source. In VBA or
'Visual Basic, you will need to add a reference to the CDO 1.21 library
'to use this procedure

'Reference Required:
'[Microsoft CDO 1.21 Library]
'C:\Windows\System32\CDO.DLL

' Outlook objects
Dim objApp As Outlook.Application
Dim l_Msg As MailItem
Dim colAttach As Outlook.Attachments
Dim l_Attach As Outlook.Attachment
Dim oSession As MAPI.Session
' CDO objects
Dim oMsg As MAPI.Message
Dim oAttachs As MAPI.Attachments
Dim oAttach As MAPI.Attachment
Dim colFields As MAPI.Fields
Dim oField As MAPI.Field

Dim strEntryID As String

' create new Outlook MailItem
Set objApp = CreateObject("Outlook.Application")
Set l_Msg = objApp.CreateItem(olMailItem)
' add graphic as attachment to Outlook message
' change path to graphic as needed
Set colAttach = l_Msg.Attachments
Set l_Attach = colAttach.Add("c:\test\graphic.jpg")
l_Msg.Close olSave
strEntryID = l_Msg.EntryID
Set l_Msg = Nothing
' *** POSITION CRITICAL *** you must dereference the
' attachment objects before changing their properties
' via CDO
Set colAttach = Nothing
Set l_Attach = Nothing

' initialize CDO session
On Error Resume Next
Set oSession = CreateObject("MAPI.Session")
oSession.Logon "", "", False, False

' get the message created earlier
Set oMsg = oSession.GetMessage(strEntryID)
' set properties of the attached graphic that make
' it embedded and give it an ID for use in an IMG tag
Set oAttachs = oMsg.Attachments
Set oAttach = oAttachs.Item(1)
Set colFields = oAttach.Fields
Set oField = colFields.Add(CdoPR_ATTACH_MIME_TAG, "image/jpeg")
Set oField = colFields.Add(&H3712001E, "myident")
oMsg.Fields.Add "{0820060000000000C000000000000046}0x8514", 11, True
oMsg.Update

' get the Outlook MailItem again
Set l_Msg = objApp.GetNamespace("MAPI").GetItemFromID(strEntry ID)
' add HTML content -- the IMG tag
l_Msg.HTMLBody = "IMG align=baseline border=0 hspace=0 src=cid:myident"
l_Msg.Close (olSave)
l_Msg.Display

' clean up objects
Set oField = Nothing
Set colFields = Nothing
Set oMsg = Nothing
oSession.Logoff
Set oSession = Nothing
Set objApp = Nothing
Set l_Msg = Nothing

End Function
--------------------


--
deko
http://forums.slipstick.com


  #5  
Old March 18th 10, 10:47 PM posted to microsoft.public.outlook.program_forms
deko[_2_]
external usenet poster
 
Posts: 6
Default Template or Form?


Thanks for the reply. I should have mentioned that I need to include
embedded images in the HTML emails messages.

I'm using Access 2007 (customer database) and Outlook 2007.

The customer database is used to send email confirmations for event
registration. The idea is to send an HTML email message with a JPEG logo
and other GIFs to create a "branded" look to the message.

I can create Outlook messages from Access easily enough, but I'm not
sure how to include images.

I'm in unfamiliar territory here so I'm looking for
suggestions/examples on the best way to accomplish this goal.

That code snippet is, apparently, one way to do it. But I'm not sure
it's the best way. Outlook Templates sound interesting if they enable
use of bookmarks, were I can insert various units of data from Access
(e.g. a NameAddressBlock or something like that).

I'll have a look at the site you mentioned. I'm hoping there are folks
who have traveled this path before who might share some example code.


--
deko
http://forums.slipstick.com

  #6  
Old March 19th 10, 01:28 PM posted to microsoft.public.outlook.program_forms
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Template or Form?

Outlook custom forms don't have bookmarks, they aren't Word documents. They
also aren't real robust and can have many problems, especially when sending
them to other people over the Internet. You are definitely better off not
using them.

Steve's sample uses a lower level API (CDO) to get at properties that
weren't exposed in the Outlook object model at that time. Those are the
attachment and item properties used to embed attachments from code in this
case. With Outlook 2007 you can use the new PropertyAccessor to avoid using
CDO, which has security restrictions these days. It did not when Steve
supplied that code sample.

What that code is doing is attaching an image file and setting 2 attachment
properties. One is PR_ATTACH_MIME_TAG where the type is set to a jpeg image,
and the other is called PR_ATTACH_CONTENT_ID, where he sets a CID for the
attachment. That CID is then used in the HTML to indicate an embedded
attachment and to provide the link to the attachment for rendering. That's
done on this line: "IMG align=baseline border=0 hspace=0 src=cid:myident".

The code should work just fine as is. I personally would probably re-write
it to use pure Outlook object model code since it's for Outlook 2007, using
PropertyAccessor in place of CDO. That would eliminate the dependency on the
optional CDO 1.21 library. That code would look something like this if
rewritten to work from outside Outlook (running in Access for example):

Public Function EmbeddedHTMLGraphicDemo()
' With a nod to Neo's original code, rewritten for Outlook 2007
' and PropertyAccessor.

' Outlook objects
Dim objApp As Outlook.Application
Dim l_Msg As MailItem
Dim colAttach As Outlook.Attachments
Dim l_Attach As Outlook.Attachment
Dim oPA As Outlook.PropertyAccessor

Dim strEntryID As String

On Error Resume Next

' create new Outlook MailItem
Set objApp = CreateObject("Outlook.Application")
Set l_Msg = objApp.CreateItem(olMailItem)
' add graphic as attachment to Outlook message
' change path to graphic as needed
Set colAttach = l_Msg.Attachments
Set l_Attach = colAttach.Add("c:\test\graphic.jpg")
l_Msg.Save

Set oPA = l_Attach.PropertyAccessor
' note: these are DASL property tags, not an URLs.

' Set PR_ATTACH_MIME_TAG
oPA.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x370E001E",
"image/jpeg")

'Set PR_ATTACH_CONTENT_ID
oPA.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E",
"myident")

Set oPA = Nothing

Set oPA = l_Msg.PropertyAccessor

' Set HideAttachments
oPA.SetProperty("http://schemas.microsoft.com/mapi/id/{0820060000000000C000000000000046}/8514000B",
true)

l_Msg.Save

' add HTML content -- the IMG tag
l_Msg.HTMLBody = "IMG align=baseline border=0 hspace=0 src=cid:myident"
l_Msg.Close (olSave)
l_Msg.Display

' clean up objects
Set oPA = Nothing
Set objApp = Nothing
Set l_Msg = Nothing
Set colAttach = Nothing
Set l_Attach = Nothing

End Function



--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"deko" deko.481kha@invalid wrote in message news:deko.481kha@invalid...

Thanks for the reply. I should have mentioned that I need to include
embedded images in the HTML emails messages.

I'm using Access 2007 (customer database) and Outlook 2007.

The customer database is used to send email confirmations for event
registration. The idea is to send an HTML email message with a JPEG logo
and other GIFs to create a "branded" look to the message.

I can create Outlook messages from Access easily enough, but I'm not
sure how to include images.

I'm in unfamiliar territory here so I'm looking for
suggestions/examples on the best way to accomplish this goal.

That code snippet is, apparently, one way to do it. But I'm not sure
it's the best way. Outlook Templates sound interesting if they enable
use of bookmarks, were I can insert various units of data from Access
(e.g. a NameAddressBlock or something like that).

I'll have a look at the site you mentioned. I'm hoping there are folks
who have traveled this path before who might share some example code.


--
deko
http://forums.slipstick.com


  #7  
Old March 19th 10, 03:26 PM posted to microsoft.public.outlook.program_forms
deko[_2_]
external usenet poster
 
Posts: 6
Default Template or Form?


Thanks Ken! That's exactly the guidance I was looking for. I'll run
with this and post back with results...


--
deko
http://forums.slipstick.com

  #8  
Old March 20th 10, 12:05 PM posted to microsoft.public.outlook.program_forms
deko[_2_]
external usenet poster
 
Posts: 6
Default Template or Form?


I tried that code, but ended up doing something else:


Code:
--------------------
Dim olapp As Outlook.Application
Dim olmi As MailItem
Dim fso As Scripting.FileSystemObject
Dim txtstrm As Scripting.TextStream
Set fso = New Scripting.FileSystemObject
strTemplatePath = "C:\Documents\RegistrationConfirm.htm"
Set txtstrm = fso.OpenTextFile(strTemplatePath, ForReading)
strMarkup = txtstrm.ReadAll
Set olmi = olapp.CreateItem(olMailItem)
olmi.HTMLBody = strMarkup
--------------------


This works great because the .htm file is easy to edit, easy to manage,
and easy to troubleshoot. I can use things like '%CustomerName%' to
insert blocks of info from Access with Replace(strFind, strReplace). As
for images, I can just set the img tags in the .htm file... simple,
and saves bandwidth.

But just when I thought all was well, I hit a brick wall called
MS-TNEF.

Non-ms clients receiving the evil winmail.dat attachment.

Here's the header from an HTML message that renders properly on a
non-ms client:


Code:
--------------------
Message-ID: 1143470602.663191268951490408.JavaMail.wasadmin@f rrlysmtp59dmz01.ibu.geico.net
Subject: GEICO Policyholder Services: Your recent quote
MIME-Version: 1.0
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

html
headtitleConfirmation/title/head
body
...
/body
/html
--------------------


Here's what the header looks like when I use my code to send email via
Outlook:


Code:
--------------------
Message-ID: 000d31cdc5e4$32f6e445$50e4efs0$@com
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_NextPart_000_000W_01CAR7PA.36950D40"
X-Mailer: Microsoft Office Outlook 12.0
Thread-Index: AxrH2TF5Cerue/SZT7itvV9oKuK30A==
Content-Language: en-us
X-MS-TNEF-Correlator: 00000000D8046EF4AB6D23479AGE82CAEEAA3517446C2900

This is a multi-part message in MIME format.

------=_NextPart_000_100E_03CAC7RA.86450D15
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque
molestie ullamcorper convallis. Sed congue urna eu nisi consequat at

------=_NextPart_000_0075_05CAC7R9.2D2D3F50
Content-Type: application/ms-tnef;
name="winmail.dat"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="winmail.dat"

eJ8+IiYJAQaQCAAEAAAAAAABAREAAQsQBgAIAAAA5AQAAAAAAA DoAAEIgAcAGAAAAElQTS5NaWNy
b3NvZnQgTWFpbC5Ob3RlADEIAQOQBgA8DgAANAAAAAsAAgABAA AAAwAmAAAAAAALACkAAAAAAAIB
--------------------


I enjoy all the proprietary features of Outlook as much as the next
guy, but I just want to send clean HTML. I don't want my formatting
encapsulated and message bloated with TNEF.

Is there some MAPI property I can set, or some DASL schema that will
nix TNEF?

Or am I going to have to just send plain text and use a lot of
asterisks, capital letters and exclamation points?


--
deko
http://forums.slipstick.com

  #9  
Old March 20th 10, 10:39 PM posted to microsoft.public.outlook.program_forms
deko[_2_]
external usenet poster
 
Posts: 6
Default Template or Form?


I've been testing with this. So far my only complaints are 1) the
rubbish (let's be nice and call it "proprietary") HTML generated by
Outlook, and 2) Outlook requiring users to manually download images by
default.

I found an Extended MAPI Wrapper library he

http://tinyurl.com/ydo8x4p

that may address issue #1. I have not tried it yet. But it I can't find
a client that can't render Outlook's HTML, I won't bother.

For #2, I'll need to instruct users to right click the Outlook InfoBar
and select Add Sender to Safe Senders List. My guess is embedding images
(as opposed to linking to them) would NOT circumvent this security
feature.


Code:
--------------------
Dim olmi as Outlook.MailItem
If GetOutlook Then
Set olmi = m_olapp.CreateItem(olMailItem)
olmi.Recipients.Add strDistribution
olmi.Recipients.ResolveAll
olmi.Subject = strSubject
olmi.HTMLBody = GetMarkup
olmi.Send
End If
Set olmi = Nothing
Set m_olapp = Nothing
--------------------


--
deko
http://forums.slipstick.com

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Form/Template for non-Outlook users lia Outlook - Using Forms 1 October 1st 07 02:49 PM
List Box in Form Template knowshowrosegrows Outlook - Using Forms 1 December 6th 06 09:15 PM
Form Template Fi Outlook - Using Forms 2 November 16th 06 07:32 PM
Convert Template to Form [email protected] Outlook - General Queries 4 August 31st 06 02:28 PM
How do I use form fields in an email template? Ann Outlook - Using Forms 1 April 27th 06 08:23 PM


All times are GMT +1. The time now is 12:45 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2024 Outlook Banter.
The comments are property of their posters.