Using images in an HTML message

Dear All,
I want to embed 2 .gif files as part of the HTML message which is being sent from one client to another..My clients want me to give them the same effect as Outlook express utility: New Using->Select Stationery->Filename...so that the text can be typed on the image & then sent...i have hardcoded the structure of the message but the problem is that i am only able to send this message & view it only on my m/c & my e-mail id....if i send it to some other id the picture is not displayed how do i handle this
Thank You
Chaitra

import java.io.*;
import java.util.*;
import java.text.*;
import javax.mail.*;
import javax.servlet.*;
import javax.activation.*;
import javax.servlet.http.*;
import javax.mail.internet.*;
public class MailServlet
extends HttpServlet
protected void printForm(String form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException
PrintWriter writer = response.getWriter();
form = MessageFormat.format(form,
new Object[] { request.getServletPath() });
writer.print(form);
writer.flush();
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException
printForm(request.getParameter("SendMailForm"),request,response);
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException
try
if(request.getContentType().
startsWith("multipart/form-data"))
doUpload(request,response);
else
response.sendError(
HttpServletResponse.SC_NOT_FOUND);
catch(Exception e)
PrintWriter writer = response.getWriter();
writer.println("<HR><B>Oops!</B><PRE>");
e.printStackTrace(writer);
writer.println("</PRE>");
writer.flush();
protected void doSendMessage(HttpServletRequest request,
HttpServletResponse response,
Dictionary fields)
throws IOException, MessagingException
String host = "10.10.40.6";
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
Session session =
Session.getInstance(props, null);
Message msg =
new MimeMessage(
session); /*.getDefaultInstance(
System.getProperties(),null));*/
msg.setFrom(
new InternetAddress(
(String)fields.get("from")));
InternetAddress[] tos =
InternetAddress.parse((String)fields.get("to"));
msg.setRecipients(Message.RecipientType.TO,tos);
if(fields.get("cc") != null)
InternetAddress[] ccs =
InternetAddress.parse((String)fields.get("cc"));
msg.setRecipients(Message.RecipientType.CC,ccs);
msg.setSubject((String)fields.get("subject"));
msg.setSentDate(new Date());
String msgText ="<HTML><HEAD><TITLE id=ridTitle>Eximbirthday</TITLE>";
     msgText+="<META http-equiv=Content-Type content=\"text/html; charset=windows-1252\"><BASE ";
     msgText+="href=d:/Tomcat/webapps/Project/>";
     msgText+="<META content=\"MSHTML 6.00.2600.0\" name=GENERATOR></HEAD>";
     msgText+="<BODY id=ridBody bgColor=#e7e4d9 leftMargin=0 topMargin=0 marginheight=0";
     msgText+="marginwidth=0>";
     msgText+="<CENTER></CENTER>";
     msgText+="<P></P>";
     msgText+="<TABLE cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";
     msgText+="<TBODY>";
     msgText+="<TR>";
     msgText+="<TD vAlign=top align=left colSpan=2><IMG height=69 src=\"cid:hbday.gif\"";
     msgText+="width=366 border=0></TD></TR>";
     msgText+="<TR>";
     msgText+="<TD vAlign=top align=left width=\"65%\" height=2>";
     msgText+="<br><br><FONT color=#0000ff size=5>";
     msgText+=(String)fields.get("body");
     msgText+="</font></TD>";
     msgText+="<TD vAlign=bottom align=right height=2><IMG height=394 src=\"cid:flowers.gif\"";
     msgText+="width=296 border=0></TD></TR></TBODY></TABLE>";
     msgText+="<DIV> </DIV></BODY></HTML>";
     if(null == fields.get("attachment"))
// msg.setText((String)fields.get("body"));
          msg.setContent(msgText,"text/html");
else
BodyPart body = new MimeBodyPart(),
attachment =(BodyPart)fields.get("attachment");
//body.setText((String)fields.get("body"));
          // body.setHeader("Content-Disposition", "inline; filename=flowers.gif");
          body.setContent(msgText, "text/html");
MimeMultipart multipart = new MimeMultipart("related");
multipart.addBodyPart(body);
multipart.addBodyPart(attachment);
          body=new MimeBodyPart();
          DataSource fds = new FileDataSource("D:/Tomcat/webapps/Project/hbday.gif");
          body.setDataHandler(new DataHandler(fds));
body.setHeader("Content-ID","hbday.gif");
     // Add part to multi-part
     multipart.addBodyPart(body);
          // Create 2nd part for the image
     body = new MimeBodyPart();
          // Fetch the image and associate to part
          DataSource fds2 = new FileDataSource("D:/Tomcat/webapps/Project/flowers.gif");
          body.setDataHandler(new DataHandler(fds2));
          body.setHeader("Content-ID","flowers.gif");
          // Add part to multi-part
          multipart.addBodyPart(body);
msg.setContent(multipart);
Transport.send(msg);
response.sendRedirect(response.encodeRedirectURL("/Project/OkForm.jsp"));
public void doUpload(HttpServletRequest request,
HttpServletResponse response)
throws IOException, MessagingException
String boundary =
request.getHeader("Content-Type");
int pos = boundary.indexOf('=');
boundary = boundary.substring(pos + 1);
boundary = "--" + boundary;
ServletInputStream in =
request.getInputStream();
byte[] bytes = new byte[512];
int state = 0;
ByteArrayOutputStream buffer =
new ByteArrayOutputStream();
String name = null,
value = null,
filename = null,
contentType = null;
Dictionary fields = new Hashtable();
int i = in.readLine(bytes,0,512);
while(-1 != i)
String st = new String(bytes,0,i);
if(st.startsWith(boundary))
state = 0;
if(null != name)
if(value != null)
fields.put(name,
value.substring(0,
// -2 to remove CR/LF
value.length() - 2));
else if(buffer.size() > 2)
InternetHeaders headers =
new InternetHeaders();
MimeBodyPart bodyPart =
new MimeBodyPart();
DataSource ds =
new ByteArrayDataSource(
buffer.toByteArray(),
contentType,filename);
bodyPart.setDataHandler(
new DataHandler(ds));
bodyPart.setDisposition(
"attachment; filename=\"" +
filename + "\"");
bodyPart.setFileName(filename);
fields.put(name,bodyPart);
name = null;
value = null;
filename = null;
contentType = null;
buffer = new ByteArrayOutputStream();
else if(st.startsWith(
"Content-Disposition: form-data") &&
state == 0)
StringTokenizer tokenizer =
new StringTokenizer(st,";=\"");
while(tokenizer.hasMoreTokens())
String token = tokenizer.nextToken();
if(token.startsWith(" name"))
name = tokenizer.nextToken();
state = 2;
else if(token.startsWith(" filename"))
filename = tokenizer.nextToken();
StringTokenizer ftokenizer =
new StringTokenizer(filename,"\\/:");
filename = ftokenizer.nextToken();
while(ftokenizer.hasMoreTokens())
filename = ftokenizer.nextToken();
state = 1;
break;
else if(st.startsWith("Content-Type") &&
state == 1)
pos = st.indexOf(":");
// + 2 to remove the space
// - 2 to remove CR/LF
contentType =
st.substring(pos + 2,st.length() - 2);
else if(st.equals("\r\n") && state == 1)
state = 3;
else if(st.equals("\r\n") && state == 2)
state = 4;
else if(state == 4)
value = value == null ? st : value + st;
else if(state == 3)
buffer.write(bytes,0,i);
i = in.readLine(bytes,0,512);
doSendMessage(request,response,fields);
class ByteArrayDataSource
implements DataSource
byte[] bytes;
String contentType,
name;
ByteArrayDataSource(byte[] bytes,
String contentType,
String name)
this.bytes = bytes;
if(contentType == null)
this.contentType = "application/octet-stream";
else
this.contentType = contentType;
this.name = name;
public String getContentType()
return contentType;
public InputStream getInputStream()
// remove the final CR/LF
return new ByteArrayInputStream(
bytes,0,bytes.length - 2);
public String getName()
return name;
public OutputStream getOutputStream()
throws IOException
throw new FileNotFoundException();
This is the latest version ....which again doesnt work!!!!!
Thanx..
Chaitra

Similar Messages

  • Using Safari to send HTML Mail message but Mail keeps dropping images?

    I'd like to use Safari to send html Mail messages, but when I click on File>Mail Contents... Mail opens a new window but my graphics are gone. (I'm creating the html pages using MS Word for the Mac.) I get a flash of the graphics for a second, and then they are replaced by a little blue lego. Any ideas? I've tried all kinds of mail preferences but nothing seems to help.

    Figured it out (at least one way): had to load the image to a server and then add the image as a link only (uncheck "save picture with document" box).

  • Cannot display remote images in HTML messages

    Hi all.
    This has been a problem since Tiger for me and ironically, is affecting me on two macs (although I sync the two together, so whatever the problem is, I'm guessing it's been copied to both locations). Here's the deal:
    I cannot display images in my messages. If I click the checkbox (under viewing in mail prefs) "display remote images in HTML messages" I get the same behavior as if it is unchecked. I've tried checking and unchecking to no avail. My guess is a corrupted preference file, but I don't know which one. If I delete my mail prefs, will I need to do anything with regards to my mailboxes etc? I have over 3GB of offline mail, all filed away into hundreds of folders and do NOT want to mess with that.
    Any suggestions are most appreciated. I'd love to see my images again without clicking on the "load images" button for EVERY email.
    Thanks,
    Rob

    I can't believe there's no answer for this at Apple Support! (I looked.) On my MacBook with Leopard (10.5.6 and Mail 3.5) the problem is fairly recent - I only noticed it a few days ago. Unchecking and rechecking the Display remote images in HTML messages does not work, and neither does restarting the computer (I rarely do, preferring to put it to sleep.) Before I removed the plist I thought I'd check here first, having the same reasons for reluctance as xrob - and a good thing I did, too. I'd hate to have the same (bad) experience as someone who already tried it. The only thing I can think that I changed recently was to add SSL support to (all) my accounts. Could that be the culprit? I guess not. I removed "use SSL" on one of the accounts but it changed nothing, except for the port number. I closed and re-opened Mail but did not restart the computer. And, where do you find the "load images" button?

  • In Mail 3.6 remote images in HTML messages display as blue squares with ? even though checked in viewing references.

    In Mail 3.6 remote images in HTML messages display as blue squares with ? even though checked in viewing references.

    Nurit,
    The point is that that button should not be there, if the preference setting is as you say. This indicates the preference setting is stuck, and that is what I was trying to help you resolve.
    The full purge is done as follows:
    Quit Mail, and in the Finder open Home/Library and locate the Mail folder. Control-click over the Mail folder, and choose Duplicate -- then drag the resulting copy to the Desktop for temporary backup. Next, open Home/Library/Preferences and find the com.apple.mail.plist file and drag it to the desktop.
    Relaunch Mail, which will open as though new, and when prompted to import anything DECLINE. Instead, re-enter your account info, and Mail will re-discover the account folders for your accounts, and all should be well, after setting preferences as you desire.
    Ask any needed questions, and keep us posted.
    Ernie

  • Error message when trying to use image processor in CS2

    Hi
    I am trying to use image processor to condense 500 proofs for my website - however although I have done many times before with no problem, now when I hit the Image processor button before I even get to key in details it is bringing up the sorry something major has happened message and I can't continue - the details of this message are as follows - ref error : this.dlgMain.ddset on Change is not a function :810 - does this mean anything to anyon? Any ideas on how to overcome would be much appreciated.
    thanks

    Go to Russell Brown's website and download his package for CS2. His 1-2-3 Processor is much more flexible than the one provided by Photoshop.

  • How to display an image on the HTML page by using applet

    Dear friends,
    I am now writing an java applet, I want to display an image on the HTML page, and tried the following commands:
    {color:#ff00ff}{color:#000000}Image map; //put in the class definition
    map=getImage(getCodeBase(),"hhh.gif"); //put in the function of init()
    g.drawImage(map,0,300,this); //put in the function of paint(){color}
    {color}
    However, when I run it, the image wasn't displayed at all.
    I hope who guys ever come across this problem could help me to solve it. Thank you in advance!
    Hawaii

    Hi,
    I am no expert on Images
    but
    from personal exp.
    are you sure that map actually contains the image?
    try using
    ImageIcon ii = ImageIcon(String name);
    map = ii.getImage();I saw a tutorial on images i think on sun
    where they use ImageIcon to load the image

  • Hello my name is jose quant, and let me know how I can use CAMERA RAW adobe bridge because the bridge use and want to open a camera raw image, I get a message that says: MAIN BRIDGE aplicaion NOT ACTIVATED. BRIDGE REQUIRES A PARTICULAR PRODUCT HAS BEGUN A

    Hello my name is jose quant, and let me know how I can use CAMERA RAW adobe bridge because the bridge use and want to open a camera raw image, I get a message that says: MAIN BRIDGE aplicaion NOT ACTIVATED. BRIDGE REQUIRES A PARTICULAR PRODUCT HAS BEGUN AT LEAST ONCE TO ACTIVATE THIS FEATURE. I wonder what that means?
    I use a lapto (windows 7) 64-Bit operating system.
    Thank you,
    my email is: [email protected], if you send me the answer to my query

    You need to activate Photoshop.
    Mylenium

  • Just purchased Nikon D610. tried to import 3 images and got this message: The files are not recognized by the raw format support in Lightroom. How do I fix this frustrating problem. Have been using Lightroom for years also Nikon products without any prior

    How do I import images. Have a message that says: The files are not recognized by the raw format suppot in Lightroom. Am using a Mac version 10.9.4. the import is from a new Nikon D610. Am using LR 4.4 Please help Adobe is useless as a support.

    Each camera must be supported explicity and your LR version is years older than your camera.
    According to Adobe's Camera-support page, you need at least LR 5.3 to work with your D610 NEFs in LR:
    Camera Raw plug-in | Supported cameras
    If you don't want to upgrade to LR 5, or can't due to your OS being too old, then it might work to use the latest DNG Converter and create DNGs from your NEFs, which should open in LR 4.x.  You can find the DNG Converter here:  http://www.adobe.com/downloads/updates

  • My bookmarks suddenly are not accessible. Each time I try to use a bookmark, the following message comes up on the error page: The requested URL /exec/obidos/subst/home/home.html/103-3592028-6560639 was not found on this server. The page error is ident

    My bookmarks suddenly are not accessible. Each time I try to use a bookmark, the following message comes up on the error page: The requested URL /exec/obidos/subst/home/home.html/103-3592028-6560639 was not found on this server. The page error is identified as "ERROR 404" I tried a clean install of the latest version; no luck. looked at plug-ins & add-ons; no luck
    == User Agent ==
    Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)

    Hi Mac Attack,
    My computer will not disconnect from the internet.  It seems to find a clone router and continues even when I shut down and unplug my my own home iy
    Your main question was 'chopped' in the title. Please reply in the body of a reply box with the full question and anything you have tried. And no, the long report was not helpful .
    If the same website is opening each time you launch a browser (Safari?) hold down the shift key as you launch to prevent previous pages from opening.
    Have a look at your settings in Safari > Preferences. Especially General and Privacy.
    Reset Safari to remove cookies and other stored data.
    System Preferences > General
    Have a look at your settings in System Preferences >  Security & Privacy.
    Call back with more questions.
    Regards,
    Ian

  • Using WEB Output HTML Gallery and uploading using ftp upload the HTML page views correctly but images only display the alt tag?

    Using WEB Output HTML Gallery and uploading using ftp upload the HTML page views correctly but images only display the alt tag in the browser window?

    After a little investigation, I discovered that PNGs also do not render correctly in IE7 in similar circumstances.
    I ended up using Levels in Photoshop to bring the output blacks up to "5", saved the images as PNGs, modified the HTML from .jpg to .png, and that seems to have covered up the problem well enough.
    By the way, I did confirm that IE8 beta 2 renders the images correctly.
    Brian

  • The backup disk image "/Volumes/Time Capsule Disk/Earl Burroughs's MacBook Pro.sparsebundle" is already in use. This is the message I get when it tries to back up, it had been working fine prior to this.....

    The backup disk image “/Volumes/Time Capsule Disk/Earl Burroughs’s MacBook Pro.sparsebundle” is already in use. This is the message I get when it tries to back up, it had been working fine prior to this.....

    The Backup disk image ... sparsebundle ... is already in use.

  • Error with list styles using image bullets

    I cannot use list styles with image bullets in the mapping of
    Framemaker documents. If I define and map a format with image
    bullets, then Robohelp creates the correct HTML/CSS code but during
    the Webhelp output forgets to copy the used image files to the
    required locations. It is possible to manually copy the image files
    into the output then the webhelp displays correctly but this is no
    possible process for us on a regular basis.

    Hi
    It's to hard to Mind-Read.
    What did the Error Message say ?
    You are aware of the 99 photos per SlideShow limit in iDVD ?
    I do My SlideShows in
    • iMovie HD6 (or FinalCut) or
    • FotoMagico
    as there are less limit's here
    Yours Bengt W

  • Kmail doesn't correctly redirect html messages

    Hey everyone,
    I would like to redirect an HTML message that comes into my KMail as a MIME email.  In KMail, the original message has two body parts in the bottom pane, one Plain Text and one HTML.  However, when I redirect the message, it puts the Plain Text part as the body part and makes the HTML part an attachment.  Is there a way to perfectly maintain the HTML message when redirecting?  Thanks!

    Sorry if I wasn't clear... the navigation works correctly; I get to the page I'm tyring to get to.  One of the things that page should do is display an image, the I use a URL parameter to build the image file name to retrieve.  The link in the first page is something like <a href="gallery.php?pg=1">.  Works fine if the first page (the one I'm navigating from) is a PHP page, doesn't work (with the same code which is only HTML) if the page is an HTML page.

  • Composing an html message

    I wasn't able to find the answer for this question in the archives - there seemed to be a link which was no longer accessible.
    I'm trying to compose an email to send out to my clients; I wanted to use html to make it pretty, add links, photos, etc. I composed it using BBEdit, opened it in IE and everything looks great. However, if I copy and paste the html into mail and send it along to myself as a test, it just comes through as code, not images and rich text (and yes, I have that selected).
    The one relevant topic I found made it sound like Mail users can't compose html emails? But this seems really wack to me, especially as all html messages I receive in Mail come through in lovely color.
    Any ideas?

    hi, Allan, thanks for your help.
    I see what you and Apple are saying about html and its accessibility problems (as well as people not wanting to receive advertisements in their email), BUT I myself subscribe to many newsletters, etc. via my email account (downloaded to Mail), and enjoy getting graphics, formatting, colors, links etc. in html format. Much more interesting and energetic than standard text.
    And I find it hard to believe that it's impossible for me to do something similar, on a very small, personal basis, to give my small business some flair, using Mail.
    It has been recommended that I open a gmail account and use their capabilities to send html compositions to my clients. Which I am not thrilled about. I know everyone receives html messages differently, and some end users will end up with just code (similar to what I see when I check my POP email account via their webmail and not Mail), but obviously many companies are using html composition in some capacity without major problems. It seems strange that Apple would tell its customers they can't do that - sending them to Gmail or a Microsoft program for it?
    Oh, and I usually do use Safari - IE is the default set for the "view in browser" action in my BBEdit (which, you're right, would be a good idea to update).
    I don't have Tiger yet so I'm not totally clear on your recommendation - are you saying that once I get Tiger Mail, I will be able to copy and paste from BBEdit to a Mail message and send it, resulting in prettily formatted html messages sent? (regardless of how the end user views them) Or is it just through Safari (which would also work fine).
    And there's no way people want to receive newsletters and updates in a PDF file form, I can tell you that right now. Attachments make people (especially PC users!) nervous.
    I suppose I can try using a friend's Tiger Mail program to send email in the way I am trying to (through Safari). Seems like a lot of hassle, but that's progress for you.
    emac   Mac OS X (10.3.9)  
    emac   Mac OS X (10.2.x)  
    emac   Mac OS X (10.2.x)  

  • HTML messages with SMTPClient

    I'm trying to send HTML messages using the older SMTPClient class that comes with the earlier JDK's. I use an older version of CodeWarrior to write my code and it has problems with the new SDK. So I haven't downloaded the JavaMail API yet, it looks to me like this SMTPClient does everything I need. But I'm having problems sending HTML messages. I test my code by sending the messages to my own Outlook Express account. Outlook express interprets very simple HTML messages correctly, but as soon as I add more complicated tags it stops interpreting the message as HTML and just prints out the HTML source as plain text. This works fine:
    msg.println("<html><body bgcolor=#D67689>");
    msg.println("This works Fine!");
    msg.println("</html>");
    But I want to put together a slicker message than that. As soon as I add more code to the message, it is not interpreted properly.
    This does not work:
    msg.println("<html><body bgcolor=#D67689>");
    msg.println("Now I just get plainText!");
    msg.println("<img border=0 src=http://members.shaw.ca/bryantronsgard/IMAGES/FlowerBanner.jpg width=467 height=199>");
    msg.println("</html>");
    Do you have to follow some stricter tag schema when sending HTML over SMTP? Is there some trick I am missing?

    I know nothing of this SMTPClient, but if it doesn't support setting a message's content type to "text/html" then it doesn't do everything you need.

Maybe you are looking for

  • Can't print to Windows 7 shared printer from Mac OS Lion

    Dear all, I would like to share my experience battling to figure out how to print to Windows 7 shared printer from Mac OS Lion. Myself had this problem and looking throughly in internet without success. But finally I figured out the solution by mysel

  • How to override the create method invoked by a create form?

    Hello everyone, I'm using ADF Faces and have the next question: How can I override the create method which is invoked by a create form to preset an attribute in the new row (the preset value is not fixed, I have to send it to the method as a paramete

  • How can I delete autofill e-mail addresses?

    I have bad e-mail addresses that auto-pop up that I would like to delete.

  • 10g installation error on AIX 5 64bit

    Hi everyone, Has anyone seen this problem before? tried to install 10g client on AIX 5.3, DISPLAY has been set and xclock can be displayed on the screen, but onece runInstaller a error came up and OUI didn't appear. the log file didn't show any error

  • Hide top level aggregation result

    Hi Experts, It is possible to hide intermediate results for aggregation using method SET_GROUP_AGGR_DISPLAYED of class CL_SALV_WD_CONFIG_TABLE (Interface IF_SALV_WD_FIELD_SETTINGS ). Is it possible to hide the top level aggregation? I only want to di