Solved

With SendObject, how do you send html formated email ?

Posted on 2002-03-09
11
638 Views
Last Modified: 2010-08-05
In MSaccess I create an email using:
DoCmd.SendObject acReport, stDocName, acFormatHTML, Cust_email, , , MyTitle , MyWaffle

Where Mywaffle is a long text string that forms the message of the email.

This is plain text using vbcrlf and vbtab to lay out the message.

I now want to create the message in html to get it to look better; how do I do that?

How do you imbed the html document into the email message?

I have created a template file, but not sure how to get the data (using visual basic) to the variable
ie how do a populate <!--AcessTemplate_Body-->      with data?

Or do you just put the html tags in the string (mywaffle), if so what setting in outlook do you need to change to get it to work?
0
Comment
Question by:perrybond
  • 7
  • 3
11 Comments
 
LVL 6

Accepted Solution

by:
xSinbad earned 300 total points
ID: 6853734
You could create a html file and then attach it to an email like this;

use OPEN to create the file

open "filename.html" for input as #1
write #1, MyWaffle ' String with html tags in it
close #1

and then using some code like this to attach it to an email.

Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
   Dim objOutlook As Outlook.Application
   Dim objOutlookMsg As Outlook.MailItem
   Dim objOutlookRecip As Outlook.Recipient
   Dim objOutlookAttach As Outlook.Attachment
   
   ' Create the Outlook session.
   Set objOutlook = CreateObject("Outlook.Application")
   
   ' Create the message.

   Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
   
   With objOutlookMsg
        ' Add the To recipient(s) to the message.
        Set objOutlookRecip = .Recipients.Add("Nancy Davolio")
        objOutlookRecip.Type = olTo
       
        ' Add the CC recipient(s) to the message.
        Set objOutlookRecip = .Recipients.Add("Michael Suyama")
        objOutlookRecip.Type = olCC
       
       ' Add the BCC recipient(s) to the message.

        Set objOutlookRecip = .Recipients.Add("Andrew Fuller")
        objOutlookRecip.Type = olBCC
       
       ' Set the Subject, Body, and Importance of the message.
       .Subject = "This is an Automation test with Microsoft Outlook"
       .Body = "This is the body of the message." & vbCrLf & vbCrLf
       .Importance = olImportanceHigh  'High importance
               
       ' Add attachments to the message.
       If Not IsMissing(AttachmentPath) Then

           Set objOutlookAttach = .Attachments.Add(AttachmentPath)
       End If
       
       ' Resolve each Recipient's name.
       For Each objOutlookRecip In .Recipients
           objOutlookRecip.Resolve
       Next
       
       ' Should we display the message before sending?
       If DisplayMsg Then
           .Display
       Else
           .Send
       End If

   End With
   Set objOutlook = Nothing
End Sub
0
 

Author Comment

by:perrybond
ID: 6854355
Sorry, I did not want to add an attachment, I want to send an email where the body of the email is using html.
I receive emails html formatted so I know it is possible.
0
 
LVL 4

Expert Comment

by:wesleystewart
ID: 6855571
"Where Mywaffle is a long text string that forms the message of the email."

All you need to do is build a string that contains the html-formatted text and pass it as MyWaffle.

Are you familiar with html tags?

Wes
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:perrybond
ID: 6855997
Yes, I have no problem with the html tags.
I have written the hrml in a txt file, checked it was OK, cut and pasted it into some VBA behind MSaccess, used this as the string 'MyWaffle', edited it to include the variables to display the live data, then used sendobject.

However, as Outlook opened, the text string was displayed as is, not html formatted.

I now assume from your reply that I am doing it right in the VBA and the problem occours with the settings within outlook.

I will look into this and report back

Thanks
0
 

Author Comment

by:perrybond
ID: 6856074
This is really turning into an Outlook question, not MSaccess

In Outlook I've changed the mail settings in the options to rich text (html) and if a write a new email, it is html formatted.

When I use sendObject, the new email pops up as plain text.

Should I go and ask this question under Outlook?

Perry
0
 

Author Comment

by:perrybond
ID: 6856109
This is really turning into an Outlook question, not MSaccess

In Outlook I've changed the mail settings in the options to rich text (html) and if a write a new email, it is html formatted.

When I use sendObject, the new email pops up as plain text.

Should I go and ask this question under Outlook?

Perry
0
 
LVL 4

Expert Comment

by:wesleystewart
ID: 6856523
Rather than struggle with Docmd.Sendobject, you could use xSinbad's code to automate Outlook.  This gives you much greater control anyway.

Instead of working with the .body property, however, you will work with the .htmlbody property.  This should produce the output you're looking for.  It will look something like this:

.Subject = "This is an Automation test with Microsoft Outlook"
.HTMLBody = "This should be <b>bold</b>."
.Importance = olImportanceHigh  'High importance

This way you don't need to send an attachment.

Wes
             
     

0
 

Author Comment

by:perrybond
ID: 6856935
Thanks, this sounds a good idea, only I cannot get xsinbads code to work

I cannot even get the dims to compile.

i have some MAPI stuff that is working and creating emails; I don't really understand how it works, but cannot find any way of using html with it.

If someone could help me getting xsindads code working i would be most gratefull.

we are using MSaccess98 and Outlook98

0
 
LVL 4

Expert Comment

by:wesleystewart
ID: 6857063
From any module in design view, click >>Tools>>References.  You'll need to find a reference for Outlook 98 Type Library.  Activate this reference and all your Outlook object declarations will compile.

Wes

0
 

Author Comment

by:perrybond
ID: 6857458
Great, cracked it !!!
Thanks xsinbad for the code and thanks wes for the help.
I know I can split points, but I don't know how !
0
 

Author Comment

by:perrybond
ID: 6880023
Thanks for the code, it just took me a while to figure out it WAS what I wanted
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question