Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

GregGood (Programmer) (OP)
14 May 07 11:58
I am using a VBA module for sending email from Access through Outlook.  I am currently using a txt file for the email body but wish to us an HTML body.  I have tried simply using the HTML file but all I get is the HTML code in the body of the email (un-rendered).  Is there anyone out there who can help me?
Thank you,
Greg Good
AlexCuse (Programmer)
14 May 07 12:32
Can you show the code you are using now?

Hope this helps,

Alex

Ignorance of certain subjects is a great part of wisdom

GregGood (Programmer) (OP)
14 May 07 12:46
Hi Alex,
This is what I am currently using:
Public Function SndLPEmail()

Dim db As DAO.Database
Dim MailList As DAO.Recordset
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim Subjectline As String
Dim BodyFile As String
Dim fso As FileSystemObject
Dim MyBody As TextStream
Dim MyBodyText As String


Set fso = New FileSystemObject


 ' First, we need to know the subject.
 ' We can't very well be sending around blank messages...

Subjectline$ = "COMFORT MUSIC DRAMATICALLY LOWERS PRICES!!!"
' Subjectline$ = InputBox$("Please enter the subject line for this mailing.", _
'                 "We Need A Subject Line!")

 ' If there's no subject, call it a day.


If Subjectline$ = "" Then
    MsgBox "No subject line, no message." & vbNewLine & vbNewLine & _
        "Quitting...", vbCritical, "E-Mail Merger"
    Exit Function
End If
    
    
 ' Now we need to put something in our letter...
    
 BodyFile$ = "s:\gtg\Price_Drop_Apr07.htm"
    
'BodyFile$ = "s:\gtg\EmailLowerPrices.txt"
' BodyFile$ = InputBox$("Please enter the filename of the body of the message.", _
'             "We Need A Body!")

 ' If there's nothing to say, call it a day.

If BodyFile$ = "" Then
    MsgBox "No body, no message." & vbNewLine & vbNewLine & _
         "Quitting...", vbCritical, "I Ain't Got No-Body!"
    Exit Function
End If

 ' Check to make sure the file exists...
If fso.FileExists(BodyFile$) = False Then
    MsgBox "The body file isn't where you say it is. " & vbNewLine & vbNewLine & _
           "Quitting...", vbCritical, "I Ain't Got No-Body!"
    Exit Function
End If

   ' Since we got a file, we can open it up.
    Set MyBody = fso.OpenTextFile(BodyFile, ForReading, False, TristateUseDefault)

   ' and read it into a variable.
    MyBodyText = MyBody.ReadAll

   ' and close the file.
    MyBody.Close

   ' Now, we open Outlook for our own device..
    Set MyOutlook = New Outlook.Application


 ' Set up the database and query connections

    Set db = CurrentDb()

    Set MailList = db.OpenRecordset("MyEmailAddresses")

 ' now, this is the meat and potatoes.
 ' this is where we loop through our list of addresses,
 ' adding them to e-mails and sending them.

    Do Until MailList.EOF

        ' This creates the e-mail
        
           Set MyMail = MyOutlook.CreateItem(olMailItem)
            
            ' This addresses it
            MyMail.To = MailList("Email")
            
            'This gives it a subject
            MyMail.Subject = Subjectline$
            
            'This gives it the body
            MyMail.Body = MyBodyText


            'If you want to send an attachment
            'uncomment the following line

            'MyMail.Attachments.Add "S:\gtg\Price_Drop_Apr07.doc", olByValue
            'MyMail.Attachments.Add "S:\gtg\Price_Drop_Apr07.pdf", olByValue

            ' To briefly describe:
            ' "c:\myfile.txt" = the file you want to attach
            '
            ' olByVaue = how to pass the file.  olByValue attaches it, olByReference creates a shortcut.
            '      the shortcut only works if the file is available locally (via mapped or local drive)
            '
            ' -1 = the position in the outlook message where to attachment goes.  This is ignored by most
            '      other mailers, so you might want to ignore it too.  Using -1 puts the attachment
            '      first in line.
            '
            ' "My Displayname" = If you don't want the attachment's icon string to be "c:\myfile.txt" you
            '      can use this property to change it to something useful, i.e. "4th Qtr Report"



            'This sends it!
            MyMail.Send

            'Some people have asked how to see the e-mail
            'instead of automaticially sending it.
            'Uncomment the next line
            'And comment the "MyMail.Send" line above this.

'            MyMail.Display


        
    'And on to the next one...
    MailList.MoveNext

 Loop

 'Cleanup after ourselves

Set MyMail = Nothing


'Uncomment the next line if you want Outlook to shut down when its done.
'Otherwise, it will stay running.

'MyOutlook.Quit
Set MyOutlook = Nothing

'MailList.Close
'Set MailList = Nothing
'db.Close
'Set db = Nothing

End Function
Remou (TechnicalUser)
14 May 07 12:59
Have you tried .HTMLBody, rather than .Body?
GregGood (Programmer) (OP)
14 May 07 13:42
Remou,
I have not tried .HTMLBody  I will do that now.  Thanks for the tip.
Greg Good
GregGood (Programmer) (OP)
15 May 07 12:13
Remou,
I used .HTMLBody and I did get the document to render in the Email. The only problem that remains is that I have a picture at the top of the page that is not coming through. When I browse the html page, the picture is there but all I have is a place holder in the email (no picture). Any thoughts?
Thanks for your help,
Greg Good
Remou (TechnicalUser)
15 May 07 12:49
It works for me with Office 2000. Just thinking ... is the image local? Does the image work when you build an email manually? What version of Office are you using?
GregGood (Programmer) (OP)
15 May 07 16:47
Hi Remou,
I have 2000 pro at home and xp pro at work and both are failing.  I've tried different things with the image.  I have it in a directory and it is also imbedded in the Word doc that I'm using to create the html page.  How would I build the email page maually?  I tried opening a new email page and then cutting and pasting the html page into the emal while the html page was rendered.  The picture is still missing.  I have a feeling that it's going to be something simple but it's sure got me for now.
Thanks again for your help,
Greg
Remou (TechnicalUser)
15 May 07 16:59
That, I think, may be where your problem is; Word can do dreadful things to HTML. Open the HTML File with notepad and manually change the image source to the name of the directory where the image is stored.
GregGood (Programmer) (OP)
15 May 07 18:36
I went in, as you suggested, and checked the address of the picture in the html code; it looks ok and works fine when I open the page with a browser.  I'm wondering if the picture must be in a particular directory in order for Outlook to see it as it is rendering the page?
Greg
Remou (TechnicalUser)
15 May 07 18:45
I don't believe so. I am still wondering about Word.

This is what I used to test:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>

<BODY>

<IMG SRC="C:\Docs\Pic.bmp" Width="80" Height="50">

<P>Hello!</P>
</BODY>
</HTML>
GregGood (Programmer) (OP)
15 May 07 19:12
Much simpler than what I've got.  I'll make some changes and let you know.
Thanks,
Greg
GregGood (Programmer) (OP)
15 May 07 19:44
Remou,
Well, by doing what you suggested I was able to see the picture in the outgoing email (big step) and when I sent the email to myself I was able to see the picture in the received email (another big step)!  When I sent the email to someone else, however, the picture was, again, nowhere to be seen.  It seems like the picture must be embedded in the in the email source so that it can be displayed no matter where it goes.
Getting closer.
Thank again,
Greg
Remou (TechnicalUser)
16 May 07 6:18
Greg
Try this.

Access

CODE

   MyMail.Attachments.Add "C:\Docs\Pic.bmp", olByValue
   'This gives it the body
   MyMail.HTMLBody = MyBodyText

HTML File
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>

<BODY>

<IMG SRC="Orange.bmp"/>

<P>Hello!</P>
</BODY>
</HTML>


Some Reading
3. You could attach the images to the message and reference them with a relative path, so <img src="img1.gif"/> instead of <img src="http://servername/images/img1.gif"/>. This has the same downside as (2).

-- http://blogs.msdn.com/pcreehan/archive/2006/10/12/where-the-helo-are-my-images.aspx


Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close