How to attach a text file as an attachment to email message?

Hello Everybody,
I have a .csv file, in which details about emp-id, emp-name, e-expenses for Reimbursement and email address are stored.
My application reads this .csv file, and sends a mail to each employee with his id, salary details in text format. (by changing content type to "text/plain") The code is working fine. But,
My problem is:
The message is sent as message body to the end user.
The end user / the person who receives this mail will not be a technical person. So,
1) If he trys to take a print out of this e-mail, He get only half of it.(as no. of colums will be more than paper size).
2) I am finding alignment problem. IF employee name is too big, other columns will shift to right and data will not be exactly under column header. (it is going in zig zag way)
So, I thought sending text file with all the details as an attachment might do well.
But, I don't know how to attach a text file to email-message body.
code
try
               {               String s1="";
                              File f1 = new File(the path);
                              FileInputStream fstream = new FileInputStream(f1); //new
                              BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
                              int count=0;
                              while((s1=br.readLine())!=null )
                                             count++;
                                             //out.println("within while loop "+count);
                                             StringTokenizer st = new StringTokenizer(s1,",");
                                             if ((st.hasMoreTokens())&&(count>1))
                                        String a=st.nextToken().trim();
                                             String b=st.nextToken();
                                             String c=st.nextToken();
                                             String d=st.nextToken();
                                             String e=st.nextToken();
                                             String f=st.nextToken();
                                             String g=st.nextToken();
                                             String h=st.nextToken();
                                             String i=st.nextToken();
                                             String j=st.nextToken();
                                             String k=st.nextToken();
                                             String l=st.nextToken();
                                             String m=st.nextToken();
                                             String n=st.nextToken();
                                             String o=st.nextToken();
                                             String p=st.nextToken();
                                             String q=st.nextToken();
                                             String mail=st.nextToken();
                                             String s=st.nextToken();
                                             //out.println("b="+b+"c="+c+"d="+d+"e="+e+"f="+f+"mail="+mail);
                                             %>
<%
                                        String to =mail;
                                             String from =request.getParameter("fromadd");                                        
                                             String subject ="Statement of Expenses";
                                             String smtp ="mail.xxxxxxxxxx.com";
                                             String message="";                                        
                                             message=message.concat("EMP ID");
                                             message=message.concat("     ");
                                             message=message.concat("Name");
                                             message=message.concat("          ");
                                             message=message.concat("Dept No.");
                                             message=message.concat("     ");
                                             message=message.concat("Acc No.");
                                             message=message.concat("     ");
                                             message=message.concat("*****************************************************************************************");     
                                             message=message.concat(a);
                                             message=message.concat("     ");
                                             message=message.concat(b);
                                             message=message.concat("          ");
                                             message=message.concat(c);
                                             message=message.concat("     ");
                                             message=message.concat(d);
                                             Properties props = System.getProperties();
                                             // Puts the SMTP server name to properties object
                                             props.put("mail.smtp.host", smtp);
                                             // Get the default Session using Properties Object
                                             Session session1 = Session.getDefaultInstance(props, null);
                                             // Create a New message
                                             MimeMessage msg = new MimeMessage(session1);
                                             // Set the From address
                                             msg.setFrom(new InternetAddress(from));
                                             // Setting the "To recipients" addresses
                                        msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to, false));
                                        /* // Setting the "cc recipients" addresses
                                        msg.setRecipients(Message.RecipientType.CC,InternetAddress.parse(cc, false));
                                        // Setting the "Bcc recipients" addresses
                                        msg.setRecipients(Message.RecipientType.BCC,InternetAddress.parse(bcc, false)); */
                                        // Sets the Subject
                                        msg.setSubject(subject);
                                        // set the meaasge in HTML format
                                        msg.setContent(message,"text/plain");
                                        // Set the Date: header
                                        msg.setSentDate(new java.util.Date());
                                        // Send the message
                                        Transport.send(msg);
                                        // Display Success message
                                        result =result.concat("<tr><td>"+b+"</td>"+"<td>"+to+"</td></tr>");
                                                  }//end of if of hasmore element
                                   }// end of while loop
                    out.println(result);                    
}catch(Exception e)
                    // If here, then error in sending Mail. Display Error message.
                    result="Unable to send your message";
                    out.println("e="+e);
Any help will be appreciated.
Thanks and regards.
Ashvini

<html>
<p>
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText("Your Messages");
MimeBodyPart mbp2 = new MimeBodyPart();
FileDataSource fds = new FileDataSource("Your Attachments");
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
msg.setContent(mp);
msg.saveChanges();
msg.writeTo(System.out);
msg.setSubject(subject);
Transport.send(msg);
</p>
<B><U>See you can add above code in your program and see the magic</U></B>
Bye
regards--
Ashish
</html>

Similar Messages

  • How Do highlight text in the body of an email message in Mac Mail?

    Can anyone tell if IF and HOW I can highlight text in the body of an email message using Mac Mail (in Yosemite).  I do NOT mean MARKUP an attachment.  I want to highlight a word or phrase in the body of my email message.  I know I can change the font color, but can't seem to add a highlight!  Thanks!

    Hi,
    is is possible, - link is below. Works on Yosemite, btw.
    http://www.mihalick.us/how-to-highlight-text-in-yellow-using-apple-mail/

  • How to zip a text file and send as email attachment in SAP version 4.6c?

    Hi Guru,
    How to zip a text file in SAP version 4.6c which doesn't have class CL_ABAP_ZIP?
    Please help.
    Thanks & Regards,
    Ari

    Hi,
    Try this link
    [http://sap.ittoolbox.com/groups/technical-functional/sap-dev/sapr3dev-zip-file-from-sap-1707099?cv=expanded]
    Cheers,
    Surinder

  • How to read several text files at a time

    Dear all
          Read and write one text file is not a problem, but  what confusies me is how to read several text files at one time, in the meanwhile,
    is it possible to display the name of the text file?
    For example, assuming I want to load file" cha 1, cha 2 , cha 3, " at one time and show their names, how to hadle with it
    I have reviewed some files and it is not helpful

    Either with a 'for' loop like in the lib you have attached, or like this attached VI
    that's it
    Message Edited by devchander on 05-30-2006 05:11 AM
    Attachments:
    MULTIPLE READ.vi ‏44 KB

  • How to create a text file or XML file  and add content through  code into it...

    Hi Everyone,
    How to create a text file and add content through the code to the text file eform javascript ......orelse can we create a text file in life cycle designer...
    Else say how to create a new XML file through the code and how some content like Example "Hello World".

    You can create a text file as a file attachment (data object) using the doc.createDataObject and doc.setDataObjectContents:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.450.html
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.528.html
    You can then export the file with the doc.exportDataObject method:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.463.html
    This won't work with Reader if it hasn't been given the file attachment usage right with LiveCycle Reader Extensions.

  • Attaching a text file

    Hello,
    I have wiritten a GUI which allows a user to enter in a message in a text field called "field1", a process button is pressed by the user and the message is processed by my algorithm. The output is then displayed in another text field called "field2". This works fine,
    I would like to develop this GUI a bit further and this the problem. Instead of the user typing in the text in "field1" I would like to provide the functionality where the user can attach a text file which is then processed by my algorithm. I have made an attach button on my GUI for this purpose. The problem im having is, how to attach the file to the "field1" text field which will then be processed by the algorithm. I have included the event handler part for the attach button.
    Thanks
    public void actionPerformed(ActionEvent e)
            if (e.getSource() == attachbutton)
                         // I would like to attach a text file to this field ready to be processed by the algorithm
                     }

    http://forum.java.sun.com/thread.jspa?threadID=632246&messageID=3663618
    If you want more read File Chooser section from sun tutorial.

  • How to upload a text file from a shared folder and provide an o/p

    how to upload a text file from a shared folder and provide an o/p  containing the details in each order in the text file

    Hi,
    Use <b>GUI_UPLOAD</b> to upload a text file from a shared folder.
    Use <b>GUI_DOWNLOAD</b> to download data in a file on the presentation server or use <b>OPEN DATASET, TRANSFER</b> and <b>CLOSE DATASET</b> statements to download data to the application server.
    Now, I hope the code for data fetching, if required, is already present in the report.
    Reward points if the answer is helpful.
    Regards,
    Mukul

  • How to convert a text file in lower case to upper case?

    I've a beginner in java world and I just come through the tutorial in http://java.sun.com/docs/books/tutorial/essential/io/filestreams.html showing how to copy a text file:
    import java.io.*;
    public class Copy {
    public static void main(String[] args) throws IOException {
         File inputFile = new File("farrago.txt");
         File outputFile = new File("outagain.txt");
    FileReader in = new FileReader(inputFile);
    FileWriter out = new FileWriter(outputFile);
    int c;
    while ((c = in.read()) != -1)
    out.write(c);
    in.close();
    out.close();
    And I would like to ask how to covert all lower case letters in input file to upper case letter in output file at the same time of copying.
    I guess it'll be using Character.toUpperCase(c), but I don't know how to do it actually.
    Any help would be much appreciated.

    Hope this helps
    import java.io.*;
    public class Copy {
    public static void main(String[] args) throws IOException {
    File inputFile = new File("farrago.txt");
    File outputFile = new File("outagain.txt");
    FileReader in = new FileReader(inputFile);
    FileWriter out = new FileWriter(outputFile);
    BufferedReader buff = new BufferedReader(in);
    String c;
    while ((c = buff.readLine()) != null)
    out.write(c.toUpperCase());
    in.close();
    out.close();
    }

  • How to send a text file to a printer?

    Hi, I'm in dark on how to send a text file to a printer through Java Stored Procedure.
    Here are what I tried so far (OS: win 2000, Oracle: 817 or 9i2):
    1, Enable DOS command in Java Stored Proc. and try to send PRINT command there:
    public static String Run(String Command){
    try{
    Runtime.getRuntime().exec(Command);
    System.out.println("Command: " + Command);
    return("0");
    catch (Exception e){
    System.out.println("Error running command: " + Command +
    "\n" + e.getMessage());
    return(e.getMessage());
    public static void main(String args[]){
    if (args.length == 1)
    Run("print /D:\\\\enterprise\\john " + args[0]);
    else System.out.println("Usage: java OSCommand filename");
    PL/SQL wrapper:
    CREATE OR REPLACE FUNCTION OSCommand_Run(p1 IN VARCHAR2) RETURN VARCHAR2 AUTHID CURRENT_USER AS LANGUAGE JAVA NAME 'OSCommand.Run(java.lang.String) return java.lang.String';
    SQL command:
    //print /D:\\machine\printer test.txt
    I loaded the Java Stored Procedure into SYSDBS account, it failed silently, even though piece of code works fine in external JVM.
    2, Use filePrinter:
    public static String print(String printString) {
    try{
    String printerUNC = "\\\\machine\\printer";
    FileWriter fw = new FileWriter(printerUNC);
    PrintWriter pw = new PrintWriter(fw);
    pw.println(printString);
    fw.close();
    return "OK";
    }catch(Exception e){
    e.printStackTrace();
    return "Exception: " + e.getMessage();
    public static void main(String[] args) {
    try{
    String printerUNC = "\\\\machine\\printer";
    String printString = "Hello World";
    FileWriter fw = new FileWriter(printerUNC);
    PrintWriter pw = new PrintWriter(fw);
    pw.println(printString);
    fw.close();
    }catch(Exception e){e.printStackTrace();}
    I loaded it into SYSDBS too, and tried with this:
    SQL> select MY_PRINT.PRINT('HELLO from Oracle') from dual;
    MY_PRINT.PRINT('HELLOFROMORACLE')
    Exception: No such file or directory
    SQL> show user
    USER is "SYS"
    It works in external JVM too.
    What's wrong with this?
    Thanks for any help in advance,
    Charles

    Avi:
    Thanks for your response!
    I put the java code in SYS, 'cause I assume that account has max privilege. If the test is successful, I will move that to some user schema and then to deal with those privilege settings... But I'm unlucky.
    I checked Ask Tom, this is what I got from http://asktom.oracle.com/pls/ask/f?p=4950:8:1619723::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:38012348052,%7Bprinter%7D:
    ... Print file from PL/SQL ...
    If you are using Oracle8i, release 8.1 -- much can be done with Java. java
    would be able to print directly from the server.
    Looks like using Java to print out file is better than PL/SQL. But there's no more hint there! And, no new question can be asked there today either...
    I'm wondering whether we can create a socket to a printer and send the characters there directly... Anyone has experience on this?
    Thanks for all the help in advance,
    Charles

  • "how to load a text file to oracle table"

    hi to all
    can anybody help me "how to load a text file to oracle table", this is first time i am doing, plz give me steps.
    Regards
    MKhaleel

    Usage: SQLLOAD keyword=value [,keyword=value,...]
    Valid Keywords:
    userid -- ORACLE username/password
    control -- Control file name
    log -- Log file name
    bad -- Bad file name
    data -- Data file name
    discard -- Discard file name
    discardmax -- Number of discards to allow (Default all)
    skip -- Number of logical records to skip (Default 0)
    load -- Number of logical records to load (Default all)
    errors -- Number of errors to allow (Default 50)
    rows -- Number of rows in conventional path bind array or between direct path data saves (Default: Conventional path 64, Direct path all)
    bindsize -- Size of conventional path bind array in bytes (Default 256000)
    silent -- Suppress messages during run (header, feedback, errors, discards, partitions)
    direct -- use direct path (Default FALSE)
    parfile -- parameter file: name of file that contains parameter specifications
    parallel -- do parallel load (Default FALSE)
    file -- File to allocate extents from
    skip_unusable_indexes -- disallow/allow unusable indexes or index partitions (Default FALSE)
    skip_index_maintenance -- do not maintain indexes, mark affected indexes as unusable (Default FALSE)
    commit_discontinued -- commit loaded rows when load is discontinued (Default FALSE)
    readsize -- Size of Read buffer (Default 1048576)
    external_table -- use external table for load; NOT_USED, GENERATE_ONLY, EXECUTE
    (Default NOT_USED)
    columnarrayrows -- Number of rows for direct path column array (Default 5000)
    streamsize -- Size of direct path stream buffer in bytes (Default 256000)
    multithreading -- use multithreading in direct path
    resumable -- enable or disable resumable for current session (Default FALSE)
    resumable_name -- text string to help identify resumable statement
    resumable_timeout -- wait time (in seconds) for RESUMABLE (Default 7200)
    PLEASE NOTE: Command-line parameters may be specified either by position or by keywords. An example of the former case is 'sqlldr scott/tiger foo'; an example of the latter is 'sqlldr control=foo userid=scott/tiger'. One may specify parameters by position before but not after parameters specified by keywords. For example, 'sqlldr scott/tiger control=foo logfile=log' is allowed, but 'sqlldr scott/tiger control=foo log' is not, even though the position of the parameter 'log' is correct.
    SQLLDR USERID=GROWSTAR/[email protected] CONTROL=D:\PFS2004.CTL LOG=D:\PFS2004.LOG BAD=D:\PFS2004.BAD DATA=D:\PFS2004.CSV
    SQLLDR USERID=GROWSTAR/[email protected] CONTROL=D:\CLAB2004.CTL LOG=D:\CLAB2004.LOG BAD=D:\CLAB2004.BAD DATA=D:\CLAB2004.CSV
    SQLLDR USERID=GROWSTAR/[email protected] CONTROL=D:\GROW\DEACTIVATESTAFF\DEACTIVATESTAFF.CTL LOG=D:\GROW\DEACTIVATESTAFF\DEACTIVATESTAFF.LOG BAD=D:\GROW\DEACTIVATESTAFF\DEACTIVATESTAFF.BAD DATA=D:\GROW\DEACTIVATESTAFF\DEACTIVATESTAFF.CSV

  • How to open a pdf file and then attach it with images

    I am new to Indesign Server.
    I'm currently working on a pdf.
    I have a white blank pdf template.
    that I want to attach/glue it with images.
    How to open a pdf file and then attach it with images.
    Please, help me.
    Thanks.

    First step would be to make yourself familiar with InDesign desktop version.
    Whatever you intend to achieve, do it there manually. (see regular app docs or forums)
    Then try to automate your steps with scripting (see scripting docs or forum)
    If you can do it with a script in the desktop version, that script will likely also run in ID Server. (see server forum).
    If you can specify missing features not achievable thru scripting or manual use, reconsider to write a plugin (this forum).
    A seasoned C++ programmer will need a few months to learn the basics, wade thru tons of documentation etc. Alternatively consider to hire a consultant to do the development work for you.
    Dirk

  • How to read a text file using Java

    Guys,
    Good day!
    Please help me how to read a text file using Java and create/convert that text file into XML.
    Thanks and God Bless.
    Regards,
    I-Talk

         public void fileRead(){
                 File aFile =new File("myFile.txt");
             BufferedReader input = null;
             try {
               input = new BufferedReader( new FileReader(aFile) );
               String line = null;
               while (( line = input.readLine()) != null){
             catch (FileNotFoundException ex) {
               ex.printStackTrace();
             catch (IOException ex){
               ex.printStackTrace();
         }This code is to read a text file. But there is no such thing that will convert your text file to xml file. You have to have a defined XML format. Then you can read your data from text files and insert them inside your xml text. Or you may like to read xml tags from text files and insert your own data. The file format of .txt and .xml is far too different.
    cheers
    Mohammed Jubaer Arif.

  • How can I read text files from LAN if I only know the hostname?

    I'm new in Java Developing, and dont know the written classes yet. I need help, how to do the following steps?
    <p>1. How can I read text files from LAN if I only know the hostname, or IP address?
    <p>2. How to read lines from text files without read all lines from the beginning of file, just seek to a position.
    (ex. how can I read the 120th line?)
    <p>Please help!
    <p>sorry for the bad english

    I'm new in Java Developing, and dont know the written classes yet. I need help, how to do the following steps?
    1. How can I read text files from LAN if I only know the hostname, or IP address?You need to know the URL of the file. You need to know the hostname, port, protocl and relative path.
    The hostname is server, not file.
    2. How to read lines from text files without read all lines from the beginning of file, just seek to a position.Use the seek() to get to a random byte.
    (ex. how can I read the 120th line?)The only way to find the 120th line is to read the first 120 lines. You can use other file formats to find the 120th line without reading the whole file but to need to be able to detremine where the 120th line is

  • How to read a text file through pl/sql

    How to read a text file through pl/sql

    pl/sql runs inside the database. so your file also should be on the database server file system for you to be able to read.
    check out UTL_FILE package. This is the database package to read/write files on the database server.

  • How to format a text file

    Hello I'm generating a text file in tab delimited format of frequency vs intensity. I wish to format it and save it in another text file. I'm getting my data in this format in the text file...
    1312500000.00    -6.69
    1375000000.00    -6.25
    1437500000.00    -5.94
    1500000000.00    -5.66
    1562500000.00    -5.89
    1625000000.00    -6.29
    1687500000.00    -6.45
    1750000000.00    -6.28
    1812500000.00    -5.59
    Now I'm trying to format this data into different coloums...like after every 201,401,601 or 1601(a control which tells this to vi)...I should jump to new set of coloumns, like:
    Frequency             Int.       Frequency             int.
    1312500000.00    -6.69    1312500000.00     -7.71        ...                ...               ...             ...   
    1375000000.00    -6.25
        1375000000.00    -6.55        ...               ...                ...           ...
    1437500000.00    -5.94
        1437500000.00    -7.94
    1500000000.00    -5.66
        1500000000.00    -7.66
    1562500000.00    -5.89
        1562500000.00    -4.89
    1625000000.00    -6.29     625000000.00      -9.09
    1687500000.00    -6.45
        1687500000.00    -6.40
    1750000000.00    -6.28
        1750000000.00    -6.88
    1812500000.00    -5.59
        1812500000.00    -5.89
    1375000000.00    -6.25
        1375000000.00    -5.25
    1437500000.00    -5.94     12500000.00        -5.59
    ...till 201 rows(If I input 201 in a control)
    I'm facing some problems with editing can anyone help me around.
    Attached my text file for reference
    Looking for help,
    Regards
    Attachments:
    Rohit.txt ‏2821 KB

    I don't think you need any loops and there is certainly no need o convert to numbers and back!
    (scanning and formatting operations are expensive!)
    Read the file as a plain string, then convert it to a 1D array of strings, one line per array element.
    Reshape to a 2D array of proper dimensions and transpose to fill columns first.
    Use spreadsheet string to array (now with tab as delimiter) to generate the desired string.
    Write the string to a new file.
    Here's a simple draft (LabVIEW 8.0). Look ma, no loops!
    Modify as needed.
    Message Edited by altenbach on 06-15-2007 03:29 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    columnwrapper.png ‏10 KB
    ColumnWrapper.vi ‏13 KB

Maybe you are looking for

  • Can't Install Adober AIR on iMac 10.6.8

    When i try to install on my iMac i get the following error even though I am the administrator: Sorry, an error has occured. An error occured while installing Adobe AIR.  Installation may not be allowed by your administrator.  Please contact your admi

  • Parameter form not displaying in 9i reports. Works fine in 6i!!

    Parameter form does not show up with any options mentioned in the cgicmd.dat. It works in 6i & surprisingly in 9i reports it doesn't. In 6i reports destype=cache shows the report output on screen but in 9i it doesn't, the report just sits in the cach

  • Settlement rule auto created in Production Order with Receiver Type as OIT

    Hi, I am creating a production order with material number in CO01. The system is automatically putting OIT in receiver category, in settlement rule. And its populating the child materials there. I expect the parent material to be populated in the set

  • Windows 7 start menu crashes InDesign CS5

    If I check the Windows 7 option to "Store and display recently opened items in the Start menu and on the taskbar" InDesign crashes the next time it opens. Has anyone else experienced this problem?

  • Flash and shockwave not working

    I'm running OS X version 10.3.9 and Safari version 1.3.2 (v312.6) and I recently tried to install the new version of the flash shockwave player before I realised what was going on all flash and shockwave content stopped working. I've tried everything