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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending HTML emails 1

Status
Not open for further replies.

barrylowe

Programmer
Nov 6, 2001
188
GB
I am creating a small training database at the moment to record training courses and the delegates who attend them.

One of the requirements for the system is to be able to produce emails which are sent to the attendees. These emails need to include a coporate logo so I assume they would have to be html format rather than plain text.

While I am happy enough writing the code to get the recordset containing the relevent attendees and loop through it, I have no idea where to begin getting it to create an email.

Can anyone help?
 
A few notes:
Code:
Sub SendSimpleEmail(txtTo, txtSubjectLine, txtMessage)
'References Microsoft Outlook 9.0 Object Library
Const conProcName As String = "SendSimpleEmail"
On Error GoTo ErrHandler
 
 Dim MyApp As New outlook.Application
 Dim MyItem As outlook.MailItem
 Set MyItem = MyApp.CreateItem(olMailItem)
 With MyItem
    .To = txtTo
    .Subject = txtSubjectLine
    .ReadReceiptRequested = False
    .HTMLBody = txtMessage
End With
MyItem.Display

ExitHere:
  Exit Sub
ErrHandler:
  Debug.Print Err, Err.Description
  Resume ExitHere
End Sub
 
Just tried out your code and it worked first time.

Thanks a million, that was exactly what I was looking for!
 
Out of interest, does anyone know how to insert an image into the email?
 
Have a look at the Attachments collection.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
That only seems to allow you attach an image file as an attachment to the email. I want to embed it so the picture is displayed in the body of the email.
 
You can put in in as part of the message in the same way you put an image in any HTML file, as far as I recall:
<IMG SRC="/img/pic.jpg" WIDTH="490" HEIGHT="20">
 
I tried that it works fine when viewing the emial on my machine.

However, if I try to view it on another machine, the path to the file is still "C:...../Computer.jpg" and this path doesn't exist on the other machine so it doesn't display.
 
I don't quite get the point. Do you which for another user to also send email, adding a picture to the email? I think you must either allow this user to choose the path, or set the path in some other way, for example:

strImg = "<IMG SRC='" & CurrentProject.Path & "\img\pic.jpg'>"
 
In order for the addressee to see the image, the pathname must resolve to something that they can see. Pull the image from the web, and include the full pathname to the it. e.g. http:\\your.domain.com\images\yourlogo.jpg

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
My version of Oulook puts an encoded version of the image into the source of the email when it is added in the above way, so it can be viewed by the recipient. I had not realised that this was not always the case. :-(
 
Duh[blush], my version of Outlook does that as well. How would you include that encoded version programatically?

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
I don't know, I always just point to the image using standard HTML and let Outlook worry about encoding. I suppose you could send the message and then grab the stff after "Content-Type: image/png;", I have a feeling that this might work, but it seems a lot of work. Then again, I am probably waffling.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top