Sending html emails

G

Guest

I have been asked to create a solution that will automatically email a html
newsletter to a selectable list of contacts taken from an Access 2K database.
I've programmed for SendObject before, but the email they want delivered is
html, not text with an attachment.

Can anyone offer a way to code for this?

Thanks,
BS
 
D

David C. Holley

Here's an abridged version of a function that I have that creates an
AppointmentItem. It won't be too difficult to modify it to create a
MailItem. You will need to set the following properties to utilize HTML
though...

..BodyFormat = olFormatHTML
..HTMLBody = "<HTML><H2>The body of this message will appear in
HTML.</H2><BODY>Enter the message text here. </BODY></HTML>"

If you go into VB Help for Outlook, look under
MICROSOFT OUTLOOK OBJECT MODEL
OBJECTS
M
MailItem

You should find everything that you need there. Also, if you click on
the link to the CreateItem article, you'll find a direct example that
creates a new mailItem.

Function createOutlookAppointmentFromId(lngTransportID As Long, frm As
Variant)

Dim objOutlook As Outlook.Application
Dim nms As Outlook.NameSpace
Dim mailbox As MAPIFolder
Dim targetCalendar As MAPIFolder
Dim newAppt As Outlook.AppointmentItem
Dim i As Integer

Set objOutlook = CreateObject("Outlook.application")
Set nms = objOutlook.GetNamespace("MAPI")
Set mailbox = nms.Folders(1)
Set targetCalendar = mailbox.Folders("Calendar")
Set newAppt = objOutlook.CreateItem(olAppointmentItem)

With newAppt
.Start = dteDate & " " & dteTimeScheduled
.End = dteDate & " " & DateAdd("h", 1, CDate(dteTimeScheduled))
.Subject = strPrimaryPassenger
.Location = strLocation
.Body = "INSERT BODY TEXT HERE" 'getBodyText()
.BusyStatus = olBusy
.Categories = "Reservations"
.MessageClass = "IPM.Appointment.Reservations"
.Save
End With

If Err.Number = 0 Then
createOutlookAppointmentFromId = -1
Else
createOutlookAppointmentFromId = Err.Number
End If

DoCmd.Hourglass (False)

Set newAppt = Nothing
Set targetCalendar = Nothing
Set mailbox = Nothing
Set nms = Nothing
Set objOutlook = Nothing

End Function
 

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