Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending HTML Formated E-Mail Using Outlook 1

Status
Not open for further replies.

nvr

Technical User
Oct 18, 2000
10
GB
I need to send out a whole bunch of e-mails on a regular basis. I'm OK with using DoCmd.SendObject to get them into Outlook, but I'm unsure how to go about constructing the required mail as an HTML formatted e-mail (not an attachment). Any pointers before I kick off in the wrong direction?

Thanks.

Martin.
 
What are you sending? A report?


DougP, MCP
dposton@universal1.com

Ask me how Bar-codes can help you be more productive.
 
No. It's not a report. The e-mail text is being created along the lines of "Thank you for your enquiry ..." and will include a gif logo (or hyperlink back to the website), coloured text and background. To get these features it needs to be formatted as an HTML E-Mail and will be sent from Outlook.

Thanks for you help.
Martin.
 
Are you going to send the same email to a number of recipients in a recordset? If so, you can build your email subject, body and recipients from expressions in a query.

Using VB to program Access to create emails for you in Outlook itself.

I'm using this code to produce one email for all members of Recordset "T_TRAINING_EMAIL_DATA"

I append to the recordset from a query which writes my email text from an expression.

The circulation list is held in an invisible text box "Forms![Confirm]![txtCircList]
" this code gathers the recipient list

Dim db As Database, rs As Recordset, strCircList As String
Dim lngCount As Long
Dim strMessage As String
Dim strDelSup As String
strMessage = "You are about to create an email for "
Set db = CurrentDb
Set rs = db.OpenRecordset("T_TRAINING_EMAIL_DATA")

With rs
.MoveFirst
Do While Not .EOF
strCircList = strCircList & rs.Fields("To").Value & ";"
.MoveNext
Loop
Me.txtCircList = strCircList

End With

'This code runs the email function

Dim objOutlook As Outlook.Application
Dim db As Database
Dim tb As Recordset
Dim lngCount As Long
Dim RetVal
Dim strCircList As String
' Initialize Outlook objects

Set objOutlook = New Outlook.Application
Set objNameSpace = objOutlook.GetNamespace("MAPI")
Set objDraftFolder = objNameSpace.GetDefaultFolder(olFolderDrafts)
' Get pointer to default "Drafts" Folder
Set objMailItems = objDraftFolder.Items
' Get pointer to the Items Collection

Set db = CurrentDb
Set tb = db.OpenRecordset("T_TRAINING_EMAIL_DATA", dbOpenDynaset)


While Not tb.EOF
Set objMailItem = objMailItems.Add(olMailItem) ' Add new mail into"Drafts" Folder
With objMailItem
tb.MoveLast
.To = Forms![Confirm]![txtCircList]
.CC = tb.Fields("Cc").Value
.Subject = tb.Fields("Subject").Value
.Body = tb.Fields("BodyText").Value & tb.Fields("AdditionalText").Value
.Save

' Save new mail in "Drafts" Folder
End With
tb.MoveNext
Wend

db.Close


' Free memory

Set objMailItems = Nothing
Set objDraftFolder = Nothing
Set objNameSpace = Nothing
Set objOutlook = Nothing

DoCmd.Hourglass False

You will need to change this to suit your application and set a reference to MS Outlook Object Library

HTH
Paul
 
Thanks for the code. I like your use of the DRAFTS folder. The problem is principally though one of creating an HTML formatted e-mail.

Perhaps it's easier than I thought. I haven't tried this, but should the text I create in the body of the message actually be the HTML code itself with all the tags etc? If in Outlook I had my default Mail Format = HTML, perhaps this would work.

Alternatively, is it possible to create a template HTML formatted mail manually, say held in DRAFTS Folder, and then duplicate and send this multiple times by looping through the record set.

Martin.
 
Did you ever get this code to work and send HTML formated messages.

Greg
 
my case is just the same, sending mass email but multiple recipients. Id like to send it in an Email format but i cant figure out how can merge/insert field names like &quot;regards <name1>, <name2> and the recipeints name varies too....

all this will be sent trhough MS Outlook I hope and yet this case still persist.

And Also, if i want it to use &quot;Outbox&quot; instead of Drafts folder should i just replace &quot;objdraft&quot;?

hope anyone can give me details guidelines for this...tnx
 
The problem went away, since we resorted to a UNIX based solution (not coded by me) which worked just fine. I therefore never got around to trying out my own suggestion! From an academic point of view though, I would be interested if anybody else managed to make this work.

Martin.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top