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

How to embed image in e-mail ?

Status
Not open for further replies.

leifoet

Technical User
Jan 31, 2016
203
BE
I will see an image at the end of my text e-mail.

...
myMail.textbody = myMail.textbody & "Yours sincerely," & vbCRLF
myMail.textbody = myMail.textbody & vbCRLF
myMail.textbody = myMail.textbody & vbCRLF
myMail.textbody = myMail.textbody & (image)

I was trying, but I do not know the correct code.
Is that possible in text or should I switch the e-mail to HTML-code ?

Thanks for tips (or example)
 
Images in emails will only be displayed in messages that are formatted as HTML and you can simply use a 'normal' HTML image element that links to URL. However "external" images may be blocked by spam filters. So to 'send' the image as part of the message rather than using an 'external' image you have to encode the image data in the src attribute as Base64 encoded text with

Code:
<img src="data:image/png;base64,[data]" alt="name.ext" >

instead of

Code:
<img src="URL" alt="name.ext" >
.

If it is always going to be the same image, such as a 'signature', it may be simpler to create a 'template' with "placeholders" and the encoded image already in place, with whatever mail client you use, and use that, the placeholder text is can then replaced by your script with the text required.




Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
How are you sending the email? You did not show how "myMail" is defined and what options you have set.
 
To the attention of Guitarzan => e-mail send code

Set myMail=CreateObject("CDO.Message")

myMail.From="(adress)"
myMail.To=Session("(adress)")
myMail.textbody = "Dear " & session("(first name)") & "," & vbCRLF
myMail.textbody = myMail.textbody & vbCRLF
myMail.textbody = myMail.textbody & vbCRLF
...
myMail.textbody = myMail.textbody & "Yours sincerely," & vbCRLF
myMail.textbody = myMail.textbody & vbCRLF
myMail.textbody = myMail.textbody & vbCRLF

myMail.Send
set myMail=nothing

What do you mean by "options" ?
Thanks - Leif
 
<OK, so you are using CDO>

Is there a better / easier method?
(I still have a problem adding the image)

Thx - Leifoet
 
Have you read the document at the first URL guitarzan provided?

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
>Is there a better / easier method?
When it comes to sending email in classic ASP, the best / easiest method is the one that works. CDO should be fine.

>I still have a problem adding the image
Well, what code did you try?
 
I changed the text-code in HTML => it works.
...
myMail.HTMLbody = myMail.HTMLbody & "<BR><HR>"
myMail.HTMLbody = myMail.HTMLbody & "<img border='0' src=' alt='logo' ALIGN='left'>"
myMail.HTMLbody = myMail.HTMLbody & "<BR><BR><BR><BR><BR><BR><br>"
myMail.HTMLbody = myMail.HTMLbody & "<HR>"
myMail.HTMLbody = myMail.HTMLbody & "<BR>"

Finally, I try to put the contents of the HTML mail into a 2-column table.
Do I have to define the columns in pixels or in percent? => Email should also be "readable" on smartphone screens.
An example of such an HTML mail table might make it easier.
Thanks for tips.
 
Pixels are an absolute size so do not 'adjust' to browser window dimensions



Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top