?
Solved

Sending Email with Embedded Images

Posted on 2006-05-22
15
Medium Priority
?
482 Views
Last Modified: 2008-02-01
Hi,

I would like to develop one web application for sending email. I would like to give the users an option either to embed the images or to have the full URL of the images located in www.

Now, the problem lies on the embedded images. As you all know that we need to specify the cid for it. I am also using tinyMCE for the HTML Editor. So here is my plan. Once the user has given the HTML, I am going to parse it in Java side and replace all those <img> with cid and I guess that they need to upload the files to the server.

Is that the best way? Anyone has better idea?

Thanks
David
0
Comment
Question by:suprapto45
  • 5
  • 4
  • 4
  • +1
15 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 400 total points
ID: 16740089
Well, embedding links is obvious and i don't think you need help with that. Embedding images is a question of using mime multiparts. Here's an example from one of those kind people who send me spam about Cialis (embedding images is a good way of defeating text-based spam filtering). You can ignore the sections put in by my AVG antivirus software. You need to do the same:

LOTS MORE HEADERS ABOVE
X-Antivirus: AVG for E-mail 7.1.392 [268.7.0/345]
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="=======AVGMAIL-4472A6615580======="

--=======AVGMAIL-4472A6615580=======
Content-Type: multipart/related; type="multipart/alternative"; boundary=------------ms090205040109030604020306

--------------ms090205040109030604020306
Content-Type: multipart/alternative; boundary=------------ms020505010601070100070704

--------------ms020505010601070100070704
Content-Type: text/plain; charset=koi8-r
Content-Transfer-Encoding: quoted-printable


--------------ms020505010601070100070704
Content-Type: text/html; charset=koi8-r
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dkoi8-r">
<META content=3D"MSHTML 6.00.2900.2180" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2><A href=3D"http://palisstionster.com/hn/?a=3D1709"><IMG alt=3D"" =
hspace=3D0=20
src=3D"cid:000b01c67ca7$4cd4b970$aa0fa8c0@alex" align=3Dbaseline=20
border=3D0></A></FONT></DIV></BODY></HTML>

--------------ms020505010601070100070704--
--------------ms090205040109030604020306
Content-ID: <000b01c67ca7$4cd4b970$aa0fa8c0@alex>
Content-Type: image/jpeg; name=cl.jpg
Content-Transfer-Encoding: base64

/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAAFAAA/+4ADkFkb2JlAGTAAAAAAf/b
AIQAEg4ODhAOFRAQFR4TERMeIxoVFRojIhgYGhgYIiceIiEhIh4nJy4wMzAuJz4+QUE+PkFBQUFB
QUFBQUFBQUFBQQEUExMWGRYbFxcbGhYaFhohGh0dGiExISEkISExPi0nJycnLT44OzMzMzs4QUE+
PkFBQUFBQUFBQUFBQUFBQUFB/8AAEQgBGgEGAwEiAAIRAQMRAf/EAT8AAAEFAQEBAQEBAAAAAAAA
AAMAAQIEBQYHCAkKCwEAAQUBAQEBAQEAAAAAAAAAAQACAwQFBgcICQoLEAABBAEDAgQCBQcGCAUD
DDMBAAIRAwQhEjEFQVFhEyJxgTIGFJGhsUIjJBVSwWIzNHKC0UMHJZJT8OHxY3M1FqKygyZEk1Rk
RcKjdDYX0lXiZfKzhMPTdePzRieUpIW0lcTU5PSltcXV5fVWZnaGlqa2xtbm9jdHV2d3h5ent8fX
5/cRAAICAQIEBAMEBQYHBwYFNQEAAhEDITESBEFRYXEiEwUygZEUobFCI8FS0fAzJGLhcoKSQ1MV
Y3M08SUGFqKygwcmNcLSRJNUoxdkRVU2dGXi8rOEw9N14/NGlKSFtJXE1OT0pbXF1eX1VmZ2hpam
tsbW5vYnN0dXZ3eHl6e3x//aAAwDAQACEQMRAD8A7hMXBM8wFWLiTyiBaCabO8JbwqqSPAVvGPFt
bwlvCqpJcBVxjxbW8JbwqqSXAVcY8W1vCW8KqklwFXGPFtbwlvCqpJcBVxjxbW8JbwqqSXAVcY8W
1vCW8KqklwFXGPFtbwlvCqpJcBVxjxbW8JbwqqUpcBVxjxbW8Jbwqe4pbj4o8B8Ee4PFubwlvCiy
tpaC4aqXpM8PxKYyK3hLeE3p1+H4piKByR96SmW8JbwhF+IBJe0Dzd/tQnZfTW831j+2P70lNreE
t4VP9odM0i5pnwJP5FZZ6FjdzCHDxBlJTPeE4cm9Jnh+JTOAaBHcpKZpJp9qSSmNnCrKzZwgM+kE
LOTS MORE OF THIS CIALIS IMAGE GARBAGE, THEN:
--------------ms090205040109030604020306--
--=======AVGMAIL-4472A6615580=======
Content-Type: text/plain; x-avg=cert; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
Content-Description: "AVG certification"

No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.392 / Virus Database: 268.7.0/345 - Release Date: 22/05/2006

--=======AVGMAIL-4472A6615580=======--
0
 
LVL 12

Assisted Solution

by:Giant2
Giant2 earned 800 total points
ID: 16740434
Here is a good article:
http://bennherrera.com/EmbeddedImage/

Hope this could help you.
Bye, Giant.
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 16740622
How to send HTML mail with inline images ?
http://www.jguru.com/faq/view.jsp?EID=97371
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 16

Author Comment

by:suprapto45
ID: 16740655
Thanks guys,

I will have a look later on

David
0
 
LVL 16

Author Comment

by:suprapto45
ID: 16748034
Hi,

I think that I did not clearly define my questions.

My application allows the user to create their own HTML (using tinyMCE - a kind like HTML Editor). Additionally, I would like to allow either provide absolute links to images or embedding images. However, for embedding images, we need to define specific things such as cid and we need to load the images. As this happens in the client-side, I would like to know your opinion on the best way to do it.

My current plan is once the user chooses the 'embedding images', once the HTML is submitted, my Java program (Servlet) needs to replace all those <img> with the <cid for embedding images and upload  the files to the server automatically.

Is that the best way to do it? Anyone has better idea? Unfortunately the users are not technical people.

Thanks
David
0
 
LVL 14

Accepted Solution

by:
hoomanv earned 800 total points
ID: 16748390
> Is that the best way to do it
perhaps. parse the html content and replace those <img> tags
0
 
LVL 16

Author Comment

by:suprapto45
ID: 16748655
Thanks hoomanv,

Anyone has any idea?

Thanks
David
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16748916
Unfortunately i don't know enough (or anything ;-)) about tinyMCE to comment
0
 
LVL 12

Assisted Solution

by:Giant2
Giant2 earned 800 total points
ID: 16749097
I agree with hoomanv,
you can parse considering the html page like a String (big) or you can use an XML approach.
HTML is a particular XML, so you can use the library using for XML. See here for examples:
http://javaalmanac.com/egs/org.w3c.dom/pkg.html

Hope this could help you.
Bye, Giant.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16749108
>>HTML is a particular XML, so you can use the library using for XML.

That's true of *x*html, not html
0
 
LVL 12

Expert Comment

by:Giant2
ID: 16749111
>That's true of *x*html, not html
Yes, but if the html has all the tag closed, it could be considered like an xml.
0
 
LVL 16

Author Comment

by:suprapto45
ID: 16749122
Thanks everyone.

I guess that it would be the best case then.

David
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16749134
>>Yes, but if the html has all the tag closed, it could be considered like an xml.

But that's fairly rare. Just one <br> would break it
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16749136
:-)
0
 
LVL 12

Expert Comment

by:Giant2
ID: 16749145
:-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month15 days, 23 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question