简体   繁体   中英

Send Email Using Classic ASP with an Embeded Image

i am making NewsLetter using the wysiwyg Editor.. it allows me to upload the Image Path and Image Path is stored in the Upload Directory.. Not When i retrieve that Image using it works in website.. the editor's value is stored in database example <br> hi

<img src="upload/acb.gif">

<br>

Hello

i am sending Email and the detail of this email is received from database and this detail is sent to visitor

he is gettion all text value but not able to see Image

so suggest me what to do..?

If you are sending emails using CDOSYS.Message, you can easily send a complete web page with embedded images using the Message.CreateMHTMLBody(url) method.

Dim Message
Set Message = CreateObject("CDOSYS.Message")

Message.From = "from@email.org"
Message.To = "to@email.org"
Message.CreateMTHMLBody "http://yourserver.org/email.html"
Message.Send()

I recently cleaned up some code I had lying around to do this and slapped it online as a "Gist" on github; hope it still helps someone!

Sending embedded images with CDOSYS

This solution uses CDO (CDOSYS / CDO.Message), with "AddAttachment", and manually controlling the properties of the attachments to make them usable from within the email HTML and to avoid them appearing as separately-downloadable attachments in an email client.

The usage is very simple, just reference the images by a local path (on the computer the code is running on) in the HTML of the message, eg:

Some Image: <img src="<EMBEDDEDIMAGE:C:\test.jpeg>" />

The code will pick up the filename, add the file as an attachment to the message, and replace the relevant part of the message HTML with the internal reference to that attachment.

You would have to add site url to img source

<img src="http://www.sitename.com/upload/acb.gif"> as the user is not accessing your site from his mailbox.

For this you can set " http://www.sitename.com/ " as a key in web.config and use in your mails.

This will resolve your problem for sure. Happy coding !!!!!!!!!!!!!

You would use AddRelatedBodyPart:

Embed Usage Create Array and Pass it in "SendMail" Function as Parameter Use in Email Body eg

Dim arrRelatedBodyPart(1)
arrRelatedBodyPart(0) = Server.MapPath(".") & "/images/barcode/bar_blk.gif"
arrRelatedBodyPart(1) = Server.MapPath(".") & "/images/barcode/bar_wht.gif"

Example

For i = 0 To UBound(arrRelatedBodyPart)
    Dim strPathAndFileName: strPathAndFileName = arrRelatedBodyPart(i)
    Dim strFileName: strFileName = GetFileName(arrRelatedBodyPart(i), "/")
    '.AddRelatedBodyPart strPathAndFileName, strFileName, cdoRefTypeId

    Set objCDOBodyPart = .AddRelatedBodyPart(strPathAndFileName, strFileName, 1)
    objCDOBodyPart.Fields.Item("urn:schemas:mailheader:Content-ID") = "<" & strFileName & ">"
    objCDOBodyPart.Fields.Update
Next

What are you using to send the email, I have had success in the past using AspEmail: http://www.aspemail.com/

It explains how to send embedded images here: http://www.aspemail.com/manual_04.html

However you will have to get it installed on your server, if you are using Shared hosting this might be a problem, if you are running your own server pretty easy!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM