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

Adding gif and jpg files to an email.

Status
Not open for further replies.

Papa Bear

Programmer
Feb 1, 2003
37
GB
Hi all
I am trying to send invoices by email. The main text works fine by building up an HTML string using all the fonts and spacing required.
My problem is inserting a company logo at the top. It is being sent as an attachment and not inserted into the body of the email. Extracts of the code follow.

Code:
Ebody = "<table width ='100%' style = 'font-size:small'>"
Ebody=Ebody + "<tr><td colspan='6' align='center'><img src=""cid:myimage.gif"" width='325' height='80' alt='Logo' /></td></tr>"

followed by more code to build up the string Ebody. Then at the end I have the following code.

Code:
Set myMail = server.CreateObject("CDO.Message")
myMail.MimeFormatted = True
myMail.From = companyRS("Email")
myMail.To = bookingRS("Email")
myMail.Subject = "Your Invoice from " & companyRS("Company_Name")

Set objBP = myMail.AddRelatedBodyPart(Server.MapPath("logo012.gif"), "myimage.gif", CdoReferenceTypeName)
objBP.Fields.Item("urn:schemas:mailheader:Content-ID") = "<logo012.gif>"
objBP.Fields.Update

myMail.htmlBody = Ebody
myMail.Send
         
Set myMail  = Nothing

Can anybody tell me why the image is being attached instead of embedded?

Thanks
 
this is de w3schools example:
Code:
<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="mymail@mydomain.com"
myMail.To="someone@somedomain.com"
myMail.TextBody="This is a message."
myMail.AddAttachment "c:\mydocuments\test.txt"
myMail.Send
set myMail=nothing
%>
 
sorry, overlooked the real problem here.
if you put the company logo on a public webserver, then you could refer to it with a <IMG src=http:// etc
Many email clients would show at first the text only version, and after explit action of the user start downloading the image.
In my view it is far better to create a PDF invoice and mail that.
I create PDF's by using the free FPDF which can be found at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top