How do i send an html page in java mail

hi everyone, i have an problem while sending html page in my java mail application.Actually it's sending the html page correctly but the thing is it doesn't display the gif files . why so ? can anyone help me. i think its b'coz of the path problem.
My requirement is like this :
I would like to send an html page to some [email protected] from my local system . for that i have written one mail application which will build an html page which is also having some gif files. And these gif files are located in my local system. when i sent to some xyz user it's not displaying the gif files . How should i give the path for that gif files. pls help me regarding this. This is Urgent.
Thanx in advance.
by
jjjavac

hi , here with i have attached my program which will work fine . What u have to do is u have to specify ur smtp host address. from address and to address. And if u want to embedd the gif file u have to specify the gif file name. It will work only in outlook and hotmail. if u have anyother doubt let me know.
import java.io.*;
import java.util.Properties;
import java.util.Date;
import javax.mail.*;
import javax.activation.*;
import javax.mail.internet.*;
import java.sql.*;
import java.text.*;
* @author Jeevan
public class EmbeddingGif {
     StringBuffer sb = new StringBuffer();
     String line;
public static void main(String[] argv) {
          new EmbeddingGif (argv);
public EmbeddingGif (String[] argv) {
          String to, subject = null, from = "[email protected]",
          cc = null, bcc = null, url = null;
//     String mailhost = null;
          String mailhost = "10.1.0.106";                    // SMTP host address
          String mailer = "SendHtmlMail";
          String protocol = "imap", host = null, user = "jeevan", password = "jeevan";
          String record = "g:/rbs/web-inf/classes/emailstore";     // name of folder in which to record mail
          boolean debug = false;
          BufferedReader in = null;
          int optind;
     for (optind = 0; optind < argv.length; optind++) {
     if (argv[optind].equals("-T")) {
          protocol = argv[++optind];
     } else if (argv[optind].equals("-H")) {
          host = argv[++optind];
     } else if (argv[optind].equals("-U")) {
          user = argv[++optind];
     } else if (argv[optind].equals("-P")) {
          password = argv[++optind];
     } else if (argv[optind].equals("-M")) {
          mailhost = argv[++optind];
     } else if (argv[optind].equals("-f")) {
          record = argv[++optind];
     } else if (argv[optind].equals("-s")) {
          subject = argv[++optind];
     } else if (argv[optind].equals("-o")) { // originator
          from = argv[++optind];
     } else if (argv[optind].equals("-c")) {
          cc = argv[++optind];
     } else if (argv[optind].equals("-b")) {
          bcc = argv[++optind];
     } else if (argv[optind].equals("-L")) {
          url = argv[++optind];
     } else if (argv[optind].equals("-d")) {
          debug = true;
     } else if (argv[optind].equals("--")) {
          optind++;
          break;
     } else if (argv[optind].startsWith("-")) {
          System.out.println(
"Usage: SendHtmlMail [[-L store-url] | [-T prot] [-H host] [-U user] [-P passwd]]");
          System.out.println(
"\t[-s subject] [-o from-address] [-c cc-addresses] [-b bcc-addresses]");
          System.out.println(
"\t[-f record-mailbox] [-M transport-host] [-d] [address]");
          System.exit(1);
     } else {
          break;
     try {
     if (optind < argv.length) {
          // XXX - concatenate all remaining arguments
          to = argv[optind];
          System.out.println("To: " + to);
     } else {
          System.out.print("To: ");
          System.out.flush();
//          to = in.readLine();
          to = "[email protected]";
     if (subject == null) {
          System.out.print("Subject: ");
          System.out.flush();
//          subject = in.readLine();
          subject = "New Bill @ " + new Date ();
     } else {
          System.out.println("Subject: " + subject);
     Properties props = System.getProperties();
     // XXX - could use Session.getTransport() and Transport.connect()
     // XXX - assume we're using SMTP
          System.out.println("mailhost :"+mailhost);
          System.out.println("from :"+from);
          System.out.println("to :"+to);
          System.out.println("cc :"+cc);
          System.out.println("subject :"+subject);
          System.out.println("bcc :"+bcc);
          System.out.println("url :"+url);
     if (mailhost != null)
          props.put("mail.smtp.host", mailhost);
     // Get a Session object
     Session session = Session.getDefaultInstance (props, null);
     if (debug)
          session.setDebug (true);
     // construct the message
     Message msg = new MimeMessage(session);
     if (from != null)
          msg.setFrom(new InternetAddress(from));
     else
          msg.setFrom();
     msg.setRecipients(Message.RecipientType.TO,
                         InternetAddress.parse(to, false));
     if (cc != null)
          msg.setRecipients(Message.RecipientType.CC,
                         InternetAddress.parse(cc, false));
     if (bcc != null)
          msg.setRecipients(Message.RecipientType.BCC,
                         InternetAddress.parse(bcc, false));
     msg.setSubject(subject);
     collect(in, msg);
//     msg.setHeader("X-Mailer", mailer);
//     msg.setSentDate(new Date());
     // send the thing off
//     Transport.send(msg);
//     System.out.println("\nMail was sent successfully.");
     } catch (Exception e) {
     e.printStackTrace();
public void collect(BufferedReader in, Message msg)     throws MessagingException, IOException {
                    BodyPart bp1=new MimeBodyPart();
                    String html="<H1>Hello from Jeevan</H1>";
                    html=html+"<img src=cid:mickey>";
                    bp1.setContent(html,"text/html");
                    MimeMultipart mp=new MimeMultipart("related");
                    mp.setSubType("related");
                    mp.addBodyPart(bp1);
                    BodyPart bp2=new MimeBodyPart();
                    DataSource source=new FileDataSource("fss.gif");
                    bp2.setDataHandler(new DataHandler(source));
                    bp2.setHeader("discrete-type","image");
                    bp2.setHeader("Content-ID","mickey");
                    mp.addBodyPart(bp2);
                    msg.setContent(mp);
                    Transport.send(msg);
     System.out.println("\nMail was sent successfully.");
//                    msg.setDataHandler(new DataHandler(     new ByteArrayDataSource(sb.toString(), "text/html")));                                        

Similar Messages

  • How to create dom treeof html page with java

    hi, all
    i met with a problem how to create dom tree of html page wih jave, that is, given a html page, how to create a dom tree of this page with java?
    thanks in advance.
    regards
    richard

    but i m using this code to create node in html file
    HTMLLIElement li = (HTMLLIElement)appHTML.createElement("LI");
    Text txt = appHTML.createTextNode(name);
    li.appendChild(txt);
    appHTML.getElementById("name").appendChild(li);
    this will display all name value which is coming from database,
    and i want to assign a hyperlink to it,
    I have id with name also so I thought that using id i will
    create javascript like
    function popup(id)
         if(id==1)
              var n1 = window.open("../list/name1.html");
         if(id==2)
              var n1 = window.open("../list/name2.html");
    this way i want to popup particular file if i can pass id value in this function
    so want hyperlink like
    name

  • How to create hyperlink in Html page using Java

    Hello every one
    I want to know that how can I create a hyperlink in Html page using java ?
    Let for example
    I have code like this and i want to give hyperlink to it using java.
    rember that i am creating node using this id="name" which give me multiple value. and i want to assign diff link to each name..?
    <tr>
    <td ><span id="name"></span>
    </tr>

    but i m using this code to create node in html file
    HTMLLIElement li = (HTMLLIElement)appHTML.createElement("LI");
    Text txt = appHTML.createTextNode(name);
    li.appendChild(txt);
    appHTML.getElementById("name").appendChild(li);
    this will display all name value which is coming from database,
    and i want to assign a hyperlink to it,
    I have id with name also so I thought that using id i will
    create javascript like
    function popup(id)
         if(id==1)
              var n1 = window.open("../list/name1.html");
         if(id==2)
              var n1 = window.open("../list/name2.html");
    this way i want to popup particular file if i can pass id value in this function
    so want hyperlink like
    name

  • How do you send a web page in safari

    How do you send a web page in safari

    File > Mail Contents of This Page
    File > Mail Link to This Page

  • Problem sending a HTML page

    How can i send a HTML by email??
    When i am sending a HTML he shows the code in the mail instead of showing the HTML page??
    Anyone knows how can i solve tyhis??

    are you setting the content type to text/html? there are plenty of examples out there (and in here). run a search.

  • How do I send an html file?

    How would I send an html document so that it opens with all its graphics inside mail. I dont want to send it as an attachment just as a newsletter type of mailing. Any ideas??

    I had the same problem. In Safari if you press apple & i it opens up a new mail message and puts the web page in it with all graphic and buttons working. So if you can host your newletter as a web page then press apple i you'll be able to send it as a html message.

  • How can i send the html animation by email for my freind(yandex,email)?

    how can i send the html animation by email for my freind(yandex,email)?

    Hello! Happy New Year to you too.
    I am not sure I understand your question properly.
    If you are making this animation for a wesite, you can include your files into an iFrame and upload all your files to your website server.
    For example add this to your html page:
    <iframe src="http://www.yourSiteName.com/folderName/index.html" style="width: 100%; height: 400px; margin-top: 10px; margin-bottom: 30px;"></iframe>
    Note: change the sizes, change your site name, folder name and html edge file name.
    If you want to just have your composition on one page by itself, then just add the folder to the root area of your server and then you can send the link by email for people to see it directly on the web. You do not need to put it in an iFrame for this. Just email the web address - so for example:
                                  http://www.yourSiteName.com/folderName/index.html
    Let me know if I understood properly and if not please give us a clear description of what you want to do.

  • How can I display the HTML page from servlet which is called by an applet

    How can I display the HTML page from servlet which is called by an
    applet using the doPost method. If I print the response i can able to see the html document. How I can display it in the browser.
    I am calling my struts action class from the applet. I want to show the response in the same browser.
    Code samples will be appreciated.

    hi
    I got one way for this .
    call a javascript in showDocument() to submit the form

  • How do I customize my html page in Dreamweaver CS5 to an Avery template that I wish to print out?

    How do I customize my html page in Dreamweaver CS5 to an Avery template that I wish to print out?

    Dreamweaver and websites do not easily match up to Avery templates.  If you are trying to develop a program for customers/etc to print labels, you should look for a script to generate a PDF file to ensure the accuracy of the printing.
    If you are trying to use Dreamweaver as a substitute to print your own labels, I would highly recommend using Microsoft Word, or Adobe InDesign for a better solution.

  • How To Call HTML Page Through Java Swing Page  ???....

    Hi All ;
    Please Can You Tell Me How To Call HTML Page Through Java Swing Page ....
    Regards ;

    Hi,
    you can use HTML fragments on a panel.
    http://java.sun.com/docs/books/tutorial/uiswing/components/html.html
    However, to integrate a browser you need 3rd party software like IceBrowser
    If you Google for: HTML Swing
    then you find many more hints
    Frank

  • How to speep up opening html page in JEditorPane

    When i call jeditorPane.setPage( URL u ) it takes about 20 seconds to show page in my JEditoPane. Could you write how to speed up loading html page. My page has 30 page. Thanks!

    When i call jeditorPane.setPage( URL u ) it takes about 20 seconds to show page in my JEditoPane. Could you write how to speed up loading html page. My page has 30 page. Thanks!

  • How do i send an html file exported from muse as email blast with images and live links?

    My question it:
    How do i send an html file exported from muse as email blast with images and live links?
    I have designed a "website" in adobe muse and exported it as an html file. I am not sure how to send my .html file in an email!
    Best,
    Nicole

    Unfortunately, the answer is, you don't. The requirements for HTML displayed in an e-mail reader are very different than those for HTML displayed in a browser. The output of Muse won't work as an HTML e-mail. You could upload the Muse site as a website and provide a link to it in an e-mail, but the HTML generated by Muse is not suitable for direct display by an e-mail program.

  • How do i send a html email from office outlook web access?

    how do i send a html email from office outlook web access?

        glenholmes,
    You've come to the right place for help. Sorry to hear that you have had hard time with your Gmail app lately. What steps have you tried to get this to work? We want to ensure that you are able to start sending those messages right away.
    ErinW_VZW
    Follow us on Twitter @VZWSupport

  • How can I send the html animation on the post(mail,google,yandex)?

    how can I send the html animation on the post(mail,google,yandex)?

    What do you mean? F you want to post your files here, put a zipped file on the cloud somewhere like dropbox, and post the link.

  • Workflow- sending a html file in a mail(outlook)

    Hi Guys,
      i want to send a html file in a mail(outlook) in workflow. whenever enduser click that file its open automatically sap inbox.
    html file belongs to a logo, if we click on that file it will automatically opens the SAP INBOX.
    this is the my requirement.
    give me suggestion for this requirement or any other solution.
    we appriciate your reply.
    Thanks
    Sankar.
    Message was edited by: sankar surya

    Unless you are prepared to zip and email every folder and
    file related to
    the page,
    exactly as it is on your computer, it would be wiser to
    upload it all to
    your hosting
    server, and send a link to the recipient.
    "2start" <[email protected]> wrote in
    message
    news:erat61$h8m$[email protected]..
    >I need to email a frame page I have created in
    DreamWeaver.. How can I do
    >that?

Maybe you are looking for