How to mail the html file using javamail????

hi
i have captured the output of a jsp page in a html file....
now i wish to send it in the mail ( *** not as an attachment)
ie
i wish the output of the jsp ie the html file to be displayed in
the message box (ie text area) ..... and then when recieved by the
receipient it shoud be displayed in the message area....
is there any way to do this ........

well as said by my fellow poster googling could have given you quick results.
Anyways,if you are unable to do so checkout the below code snippet.
SendMail.java:
===========
import java.io.File;
import java.io.FileReader;
import java.io.BufferedReader;
import java.util.Properties;
import javax.mail.Session;
import javax.mail.Message;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;  
import javax.mail.internet.MimeMessage;
import javax.activation.*;
* @Author RaHuL
* uses SMTP to send Email.
public class SendMail {
    /** Method used to read contents of html/text/XML file */
    public String readFile(String fileName){
       StringBuffer sb = new StringBuffer();
       BufferedReader input = null;
       try{
           input = new BufferedReader(new FileReader(fileName));
           String str = null;
           while ((str = input.readLine()) != null){    
                  sb.append(line);
       }catch(Exception exp){
           exp.printStackTrace();
       }finally{
              try {
                    if (input!= null)  
                      input.close(); 
               }catch (Exception ex) {
                     ex.printStackTrace();
       return sb.toString();
    /** Send an HTML Email with the specific subject to specfic toAddress based on specified fromAddress & Smtp Hostname
      * and returns true on success.
    public boolean sendMail(String toAddress,String fromAddress,String hostName,String subject,String htmlMessage,String contentType) {
       boolean flag = false;    
        try {
             String to = toAddress;
             String from = fromAddress;     
             String host = hostName;
             // Setting Mail properties
             Properties props = new Properties();
             props.put("mail.smtp.host",host);
             props.put("mail.debug","true");
             // Getting a New Instance Generated by the API
             Session session = Session.getInstance(props);
               NOTE: a Mail Session could be configured and could be got from the Container via JNDI
                     which could be a better practise.
            // Instantiate a message
            Message msg = new MimeMessage(session);
            //Set message attributes
            msg.setFrom(new InternetAddress(from));
            InternetAddress[] address = {new InternetAddress(to)};
            msg.setRecipients(Message.RecipientType.TO, address);
            // Setting Subject Type
            msg.setSubject(subject);
            msg.setSentDate(new Date());
            // Setting Content Type
            msg.setContent(contentType);
            // Set message content
            msg.setText(htmlMessage);
            //Send the message
            Transport.send(msg);
            flag = true;
        }catch (Exception mex) {
         // Prints all nested (chained) exceptions as well
            mex.printStackTrace();
     return flag;
    public static void main(String args[]){
        SendMail sm = new SendMail();
        String htmlMessage = sm.readFile("myHtmlFile.html");
        boolean flag = sm.sendMail("[email protected]","[email protected]","your.smtp.server","EMail SubJect",htmlMessage,"text/html");
        if(flag)
          System.out.println("MAIL SENT SUCCEFULLY");
         else
          System.out.println("MAIL SENDING FAILURE");                          
}NOTE:
=====
Make sure you inculde javamail & java activation libraries.
Hope that might help :)
REGARDS,
RaHuL

Similar Messages

  • Can AnyOne Please Tellme How to configure the HTML files

    This is very Urgent.
    1.I am using the WLS7.0 sp1 .I need to configure theHTML files which are in a
    different path how can I map them to the present DefaultWebAPP directory.
    2. How can I get rid of the port number when I am fully using in production mode.
    I have been posting this query since long but in vain. Please guide me

    1. I got rid of port number with link provided by the karthik.
    2.How can I create a link .The link appends to the defaultwebapp directory
    and checks from their .I need to know how to configure the
    HTML files which are not in the DefaultWebApp.But completely in directory.
    Any suggestions !!!!!!!
    Shehzad <[email protected]> wrote:
    1. You can create a link to that directory
    2. In order to get rid of port number, either boot weblogic at default
    port 80, or use Apache or Iplanet webserver, and use Weblogic plugin.
    That way all the traffic comming in from http will comein at port 80
    to the webserver, and would then be forwarded to Weblogic at whatever
    port it is booted.
    This is very Urgent.
    1.I am using the WLS7.0 sp1 .I need to configure theHTML files whichare in a
    different path how can I map them to the present DefaultWebAPP directory.
    2. How can I get rid of the port number when I am fully using in productionmode.
    I have been posting this query since long but in vain. Please guideme

  • How to embed the html file into form 6i?

    How to embed the html file into form. What control activeX should i use? please help!!!!!!

    You can use web.show_document function for this purpose. See
    form builder help topics for more details.
    Hope this helps.

  • How to update the HTML file so that we can Control our process in real time

    After installing following three steps as per the lookout 4 online help I am unable to Monitor and control the Process in HTML format, which was exported manually in lookout server.
    1) Creating a Web Client Page in Lookout
    2) Download a Lookout Web Client
    3) Setting Up Own Web Server
    My browser shows only the instance, which I have uploaded manually without any update
    Problem: How to automatically update/refresh the HTML file so that we can Monitor/Control our process in real time/bi-directional mode.

    Hi,
    It seems like your process is not updating. When you create a Web Client, it uses ActiveX which lets you control the Lookout process fully. Make sure that you run the process. You can do this by pressing CTRL+Spacebar which puts it in Run-mode. Perhaps then you may see your graphs, etc updating.
    Also, please refer to page 11-1 of the Users Manual linked below:
    http://www.ni.com/pdf/manuals/322390a.pdf
    What kind of Web Server are you using? Make sure all the settings in it are done properly. If you have LabVIEW, you can use the LabVIEW Web Server.
    Hope this information is helpful. Please let us know if you have any further questions.
    Regards,
    A Saha
    Applications Engineer
    National Instruments
    Anu Saha
    Academic Product Marketing Engineer
    National Instruments

  • How to parse a HTML file using HTML parser in J2SE?

    I want to parse an HTML file using HTML parser. Can any body help me by providing a sample code to parse the HTML file?
    Thanks nad Cheers,
    Amaresh

    What HTML parser and what does "parsing" mean to you?

  • How to display the HTML File Titles instead of File Names

    Hello All,
    I want to display the HTML file titles instead of File names in the Search Results. I've tried to give this command in the 'Visible Properties' in the 'SearchResourceRenderer' as:-
    Visible Properties: rnd:displayTitle
    However this is not working for me. If anyone has an idea of what to pass here or any other alternative to display the Titles.
    Regards
    Vaib

    Summary of steps:
    1) Standard Layout Set used: SearchResultLayoutSet
    2) Create a new layout set using ADVANCED COPY
    3) Change properties as you require
    4) Next modify the search OTH file to reflect this newly created Layout Set (under KM > root > etc > oth > search.oth edit xml file property rndLaoutSet from SearchResultLayoutSet to MyCustomSearchResultLayoutSet)
    5) Check in the document to complete the editing process if Edit Locally is used!
    6) Lastly, activate the OTH file by –
    •     Setting Debugging settings via Debugging Settings
    •     Performing a normal search
    •     Clicking Rendering information and then following link OTH Overview click on Reload
    7) Reload above reloads the OTH file and performing search again will yield the desired result
    8) To turn off the Rendering Information link remove the user id from Debugging Settings.
    Cheers
    Ankit

  • How to open the pdf file using LabVIEW program

    I want to open the pdf file using the system exe, but it is not happening . Can you help me?
    Solved!
    Go to Solution.

    In simpler version
    Mark the satisfied answer as accepted solution for your question,you mistakenly marked youself 
    Message Edited by Baji on 04-07-2009 05:03 PM
    Balaji PK (CLA)
    Ever tried. Ever failed. No matter. Try again. Fail again. Fail better
    Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.
    Attachments:
    open pdf.JPG ‏25 KB

  • How to create the trace file using run_report_object at runtime

    Dear All
    using :
    Oracel Application Server 10g
    Oracle Database 11g
    Windows XP/sp3
    I'm using run_report_object to call a report inside the form. THis report is running OK from reports builder, however it's too slow when run from Application server.
    How Can I create a trace file (at runtime) that contains the time spent in sql and formating the layout of the report ??
    Here is My code :
    repid := find_report_object('report5');
    SET_REPORT_OBJECT_PROPERTY(repid,REPORT_FILENAME,'INVOICE.REP');
    v_url :='paramform=no';
    v_url := v_url||' FROM_NO=' || :PRINT_BLOCK.FROM_NO ;
    v_url := v_url ||' TO_NO=' || :PRINT_BLOCK.TO_NO ||' FROM_DATE=' || v_from_date ||' TO_DATE='|| v_to_date ||' NO_DATE=' ;
    v_url := v_url ||:PRINT_BLOCK.NO_DATE||' IDENT=' ||:PRINT_BLOCK.IDENT_NO||' REPORT_HEADING='''||V_REPORT_HEADING||'''' ;
    v_url := v_url||' COMPANY_NO='||:global.company_no;
    SET_REPORT_OBJECT_PROPERTY(repid,REPORT_OTHER,v_url);
    SET_REPORT_OBJECT_PROPERTY(repid,REPORT_SERVER,:GLOBAL.INV_REPORT_SERVER_NAME);
    SET_REPORT_OBJECT_PROPERTY(repid,REPORT_DESFORMAT,'pdf');
    v_rep := RUN_REPORT_OBJECT(repid);
    IF rep_status = 'FINISHED' THEN
    V1:='/reports/rwservlet/getjobid'||substr(v_rep,instr(v_rep,'_',-1)+1);
    WEB.SHOW_DOCUMENT('/reports/rwservlet/getjobid'||substr(v_rep,instr(v_rep,'_',-1)+1)||'?server='||REPORT_SERVER_NAME,'_blank');
    END IF;
    Thanks a lot

    Slow running reports often are not the result of a flawed report, but rather a flawed configuration. For example:
    1. If you call your reports (from Forms) via the default or inProcess Reports Server, often because startup time is slow, it will appear that it took too long for the report to be delievered. Using a stand-alone Rep Server is the preferred way to do this.
    2. If your Forms application makes numerous calls to RRO (RUN_REPORT_OBJECT), this can tend to result in what might appear as a memory leak (although it is not). The result is delayed processing because of the excessive memory use. This problem has been overcome in Forms/Reports 11 by the use of JVM pooling. However in v10 enabling "6i compatibility" mode is the way to overcome the issue. See Note 266073.1
    3. If the report runs fine from the Builder and it is connecting to the same db as when you run it from App Server, the issue is unlikely a db problem. However, if you want to look anyway, enable sqlnet tracing.
    4. To enable Reports tracing and investigate other tuning options, refer to the Reports 10 documentation:
    http://docs.oracle.com/cd/B14099_11/bi.1012/b14048/pbr_tune.htm
    Almost forgot to mentioned this one....
    If you are using a v11 db with App Server 10, you will probably want to consider reviewing Note 1099035.1 as it discusses an issue related to performance with such a configuration.
    Edited by: Michael Ferrante on Apr 10, 2012 8:49 AM

  • How to extract the excel file using web dynapro

    Hi Expert,
       I want to know how to generate an excel file to extract the internal  data. Please give me your help.
      Thanks in advance.

    I think you you can use File download UI element. Refer following link for more info:
    [FileDownload|http://help.sap.com/saphelp_tm60/helpdata/en/09/a5884121a41c09e10000000a155106/content.htm]
    Regards,
    Saket

  • How to read the excel file using webdynpro abap?

    Hi,
    how to read and modify excel file using webdynpro abap?
    Regards,
    Pavani

    For reading excel file follow the steps :
    1. Use a File upload UI element and bind it with xstring.
    2. Now your excel will be uploaded and stored in Xstring.
    3. Convert Xstring to String data using FM 'HR_KR_XSTRING_TO_STRING'.
    4. Now split the string at new line so as to make an internal table .
      Ex . SPLIT l_string  AT cl_abap_char_utilities=>newline INTO TABLE it_table.
      here it_table is type table of string.
    5.now loop at the internal table and separate the content of this table separated by tab.
      Ex. SPLIT wa_table AT cl_abap_char_utilities=>horizontal_tab INTO TABLE it_new.
    it_new type string_table.
    6. For more info , refer this thread :
    Re: How to upload excel file in Webdynpro application using ABAP

  • How to upload an html file using jsp and jdbc

    Hi,
    im trying to upload an html page using JSP and jdbc. but of no success.
    my aim is to keep some important html pages in the database.the file size can vary.the file has to be selected from a local machine (through the browser) and uploaded to a remote machine(where the databse resides).
    any help/sample code or pointer to any helpful link is appreciated.
    thanks in advance
    javajar2003

    When uploading a file, I use a byte array as a temporary buffer..
    So, you should then be able to store the byte array in the
    database as binary data.
    example>
    //Temporary Buffer To Store File
    byte[] tmpbuffer = new byte[860];
    //Some Code To Upload File...
    //File Should Now Be In Byte Array
    //Get DB Connection and execute Prepared Statement
    Connection con=//GET DB CONNECTION;
    String sql=insert into TABLE(page) values(?);
    PreparedStatement ps=con.prepareStatement(sql);
    ps.setBytes(1,tempbuffer);
    ps.executeUpdate();
    //Close PS and Free DB Connection
    ..... and this method looks like you dont even have
    to store the file in a byte array, you can just give
    it the input stream.
    ps.setBinaryStream(int, inputStream, int);
    You may have to make several attempts at this. I have
    uploaded a file and temporarily stored it in a byte array,
    but have never from there stored it in the DB as binary
    data.. but this looks like it'll work.
    Good Luck!

  • How to parse the xml file using servlet

    My scenario is like this:
    <b>FILE-->XI-->J2EE Application</b>
    XI sends the xml file to j2ee application. My servlet receives the file in HTTPRequest string. 
    How to parse that file using servlets.I should get the xml file as it is and should be displayed in the browser.
    Can anyone please help me with code, its urgent.
    Please help me!

    Download this java code
    http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/sax/work/Echo02.java
    in your servlet code you can write
    public void doPost(req,resp){
    DefaultHandler handler = new Echo02();
    handler.parse(req.getInputStream());
    Offcourse you will need to modify the code of Echo02 class a bit to suit your requirement which would finally retrun you a string and you can then write it using
    respose.getWriter().write(responseString);

  • How to ignore the empty file using Receiver file adapter with Coma separato

    Hi,
      I am trying to create the .csv file at the receiver but when there is no data I wan to ignore the file even I do not want to create the file with comma also (I just went and check in my file system created with commas)
    Source1 -> T1
           T1
            -> S1
                  ->Field1
                  -> Field2
    Because I am using receiver side FCC populating with empty node
    Based on condition T1 is populating when condition fails I am populating target T1 and structure elements are mapped with constant. 
    Ex: Target payload when condition failed below data is populating ..
    In this I want to ignore creating the file.
    <T1>
    <S1>
    <Field1/>
    <Field2/>
    </S1>
    </T1>
    Here Is the my content conversion parameters,
    S1.fieldNames - Field1,Field2
    S1.fieldSeparator - ,
    S1.endSeprator u2013 u2018nlu2019
    I used processing tab u2018Ignoreu2019 option id did not worked. Appreciate your help. 
    Regards,
    Venu.

    Hi Raj,
       I went my receiver mapping signature tab I chagned occurance from 1 to 0..1
    then my mapping got lossed now message type level I put the condition. When my condition not satisfy I am not creatin gthe target node itself.(I mean here message type) Messages ->message1 only is creating..
    but in SXMB_MONI below error I am getting..
      <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    - <!--  Request Message Mapping
      -->
    - <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="">
      <SAP:Category>XIServer</SAP:Category>
      <SAP:Code area="MAPPING">GENERIC</SAP:Code>
      <SAP:P1>Split mapping created no messages</SAP:P1>
      <SAP:P2 />
      <SAP:P3 />
      <SAP:P4 />
      <SAP:AdditionalText />
      <SAP:Stack>Split mapping created no messages</SAP:Stack>
      <SAP:Retry>M</SAP:Retry>
      </SAP:Error>
    Thanks for your response.
    Regards,
    Venu.

  • How to find the corrupted files using javascript?

    Hi all,
    I need to run batch of files some of which were corrupted?? instead of using the method "the files which were not opened are corrupted" is there any way to find the corrupted files??
    I need to find this using javascript or apple script??
    Please some one help me..
    Regards,
    subha

    We found one datafile has corrupted by using dbv.dbv would have reported the block ids (block numbers) that are corrupted.
    query dba_extents to identify the segments that contain such blocks.

  • How to Upload the LDT file Using FND_LOAD for 'MENU','CONCURRENT PROGRAM'

    Hi,
    I have tried to upload the ldt file in one instance to other instance using the following Command
    FNDLOAD apps/apps O Y UPLOAD $FND_TOP/patch/115/import/afsload.lct file_name.ldt MENU MENU_NAME="menu_name"
    I got the Output file (LDT file),but I am not able to view in the Application once I upload this again.Same for Concurrent program also.
    Can any one help me for solving this issues. Awaiting for your valuable reply.
    Thanks,
    Prakash

    You should probably ask this in an E Business Suite forum.

Maybe you are looking for

  • Help with desk top MEMO

    My PALM Desktop software V 4.1.2  All of a suuden in Memos, the memo entries are all together line after line. They are no longer each on a line by temselves. How can I get them back?  All other types ie contacts, tasks are displaying fine. Post rela

  • How to make a pdf (form) accessible for reader in Adobe Acrobat x pro?

    Hi guys, i have bit of a problem here as i am new to the Acrobat pro X  Using Acrobat pro 9 i always could save a LiveCycle pdf form with permission to fill and save as a reader user. now i have upgraded to cs6 and i have no clue how to do that anymo

  • Aironet BR500E Bridges

    I have a Cisco Airnet BR500E Bridge connection setup between two buildings. I lost communication today and when I look at the Ethernet hub at the other location the Power Light is blinking GREEN. After resetting the power, the Bridge appears to retur

  • Consolidation of several numbers forms to one master form/

    In the past using excel as a purchasing or invoicing system I was able to consolidate several sheets into one master for by linking them together under the Data tab then Consolidate. I do not see this function any where in numbers. Can anyone help? M

  • Vector a photo?!?

    Hey everybody...WhatsUp?! Listen, quick ?.... How can I convert a photo (.jpg) to vector based using Illustrator without losing quality? This is especially important because I've started printing a lot of large-format stuff, i.e. wall-scapes billboar