
Originally Posted by
cbrsix
I have looked at these and am really not sure how to add them into my code. Any suggestions?
I use Outlook templates along with HTMLReplace and replacement strings.
I create a "TemplateData" object that holds all the data I want to be able to pass to my mailer, then take the data and feed it through the mailer a little like this:
Code:
Dim oApplication As Outlook.Application
Dim oItem As Outlook.MailItem
Dim oAccount As Outlook.Accounts
Dim signature As String
Public Function BuildTemplate(data As TemplateData)
Set oApplication = New Outlook.Application
Set oItem = oApplication.CreateItemFromTemplate(data.GetPath)
With oItem
If Int(Year(data.GetStartTime)) > 2000 Then
.HTMLBody = Replace(.HTMLBody, "INSERT_INCIDENT_START_DATE_TIME", Format(data.GetStartTime, "mm/dd/yyyy h:mm AMPM") & " EST")
Else
.HTMLBody = Replace(.HTMLBody, "INSERT_INCIDENT_START_DATE_TIME", " ")
End If
.HTMLBody = Replace(.HTMLBody, "INSERT_INCIDENT_DESCRIPTION", data.GetShortDescription)
.HTMLBody = Replace(.HTMLBody, "INSERT_BRIDGE", data.GetBridge)
.HTMLBody = Replace(.HTMLBody, "INSERT_SITUATION", data.GetSituation)
.HTMLBody = Replace(.HTMLBody, "INSERT_IMPACT", data.GetImpact)
.BCC = .BCC & "; " & data.GetBCC
.CC = .CC & "; " & data.GetCC
.subject = data.GetSubject
End With
End Function
Public Function Send()
oItem.Display
End Function
You are, of course, welcome to use whatever you like from that. There are better ways to do it, and I would do it different if I rebuilt it now, being more experienced than when I did build that. Anyway, data.GetPath points to the template being used. The template can include any decoration or formatting you want, and then simple text replacement will let you fill out the variable data you need to put in there.