How to Read An Attachment Using Java Mail

Hi
I Am Able To Read The Mail Using Java Mail ,but Unable To Read The Attachment Which Comes Along With The Mail.
Please Help Me , In Reading The Attachment.

Hi
I Am Able To Read The Mail Using Java Mail ,but
t Unable To Read The Attachment Which Comes Along
With The Mail.
Please Help Me , In Reading The Attachment.Do you mean:
- I only recieve .txt or .doc attachments and I want to see the contents? Or could you get a .jpg as well?
or
- Do you need to seperate the attachment from the e-mail and then view it?

Similar Messages

  • How to read system eventlog using java program in windows?

    How to read system eventlog using java program in windows?
    is there any java class available to do this ? or any one having sample code for this?
    Your friend Zoe

    Hi,
    There is no java class for reading event log in windows, so we can do one thing we can use windows system 32 VBS script to read the system log .
    The output of this command can be read using java program....
    we can use java exec for executing this system32 vbs script.
    use the below program and pass the command "eventquery"
    plz refer cscript,wscript
    import java.io.*;
    public class CmdExec {
    public static void main(String argv[]) {
    try {
    String line;
    Process p = Runtime.getRuntime().exec("Command");
    BufferedReader input =
    new BufferedReader
    (new InputStreamReader(p.getInputStream()));
    while ((line = input.readLine()) != null) {
    System.out.println(line);
    input.close();
    catch (Exception err) {
    err.printStackTrace();
    This sample program will list all the system log information....
    Zoe

  • How to read system evenlog using java program in windows

    How to read system evenlog using java program in windows???
    is there any java class available to do this ? or any one having sample code for this?
    Your friend Zoe

    Welcome to the Sun forums.
    >
    How to read system evenlog using java program in windows???>
    JNI. (No.)
    >
    is there any java class available to do this ? or any one having sample code for this?>You will generally get better help around here if you read the documentation, try some sample code and come back with a specific question (hopefully with an SSCCE included).
    >
    Your friend Zoe>(raised eyebrow) Thank you for sharing that with us.
    Note also that one '?' denotes a question, while 2 or more generally denotes a dweeb.

  • How to read pdf files using java.io package classes

    Dear All,
    I have a certain requirement that i should read and write PDF files at runtime. With normal java file IO reading is not working. Can any one suggest me how to proceed probably with sample code block
    Thanks in advance.

    hi I also have the pbm. to read pdf file using JAVA
    can any body help meWhy is it so difficult to read the thread you posted in? They say: java.io is pointless, use iText. So why don't you?
    or also I want to read a binary encoded data into
    ascii,
    can anybody give me a hint how to do it.Depends on what you mean with "binary encoding". ASCII's binary encoding, too, basically.

  • Want to send PDF as attachement using Java Mail

    HI,
    I am using Java mail API for sending PDF as attachment. Here is my sample code
    messageBodyPart = new MimeBodyPart();
    messageBodyPart.setDataHandler(new DataHandler("String data for PDF using iText", "text/plain" ));
    I am generating String for PDF file using iTEXT but I am unable to find out mimetype for passing into DataHandler as second paramete.
    Any idea?
    Thanks
    Shailesh

    Don't convert the data to String. It isn't text so
    you'll damage the binary content by doing that. In
    the "demos" directory of your JavaMail download
    you'll find a ByteArrayDataSource class you can use
    instead of a FileDataSource. Yes, this worked for me. I create the pdf in memory as as StringBuffer and I just changed the code from
    messageBodyPart.setDataHandler(new DataHandler(pdf.toString(), "application/pdf"));
    to
    messageBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource(pdf.toString(), "application/pdf")));
    and it worked.
    Thanks a lot for your help,
    Dennis

  • How to read Korean characters using Java program?

    In Oracle table, i am having Korean characters, how to read those characters using JDBC and insert into SQL Server?
    NLS_NCHAR_CHARACTERSET is UTF8

    What data type is the column in the Oracle table? The NLS_NCHAR_CHARACTERSET would control the encoding of NCHAR and NVARCHAR2 columns. The NLS_CHARACTERSET would control the encoding of CHAR and VARCHAR2 columns.
    Justin

  • Extract Mail Attachment using Java Mail

    Hello Friends
    A day ago I entered into Java Mail , now I am able to send mail from my Java Program.
    The help I need from you is I wanna save the attachment coming in the mail using Java.
    For eg : a mail reched my Inbox contains .xls or .csv file which I wanna save to some place.
    Plss guide me to acheive this friends.
    Regards
    Vicky

    String host = "";
    String username = "";
    String password = "";
    String srcDir = "INBOX";
    String tarDir = "";
         String subject = "";
    String filepath = "C:/Documents and Settings/name/Desktop";
    String filename = "demo";
    Properties props = System.getProperties();
    props.put("mail.host", host);
    Session session = Session.getDefaultInstance(props, null);
    Store store = session.getStore("imap");
    store.connect(host, username, password);
    Folder folder = store.getFolder(srcDir);
              Folder dFolder = store.getFolder(tarDir);
    folder.open(Folder.READ_WRITE);
              Message message[] = folder.getMessages();
              java.util.Date yesterdayDate = new Date(System.currentTimeMillis() - 24*60*60*1000);
    for (int p = 0; p < message.length; p++) {
                   java.util.Date messageReceivedDate = message[p].getReceivedDate();
                   if(messageReceivedDate.after(yesterdayDate))
                        if (message[p].getSubject().equals(subject)) {
                             Multipart mp = (Multipart)(message[p].getContent());
                             for (int i = 0, n = mp.getCount(); i < n; i++) {
    Part part = mp.getBodyPart(i);
    String disposition = part.getDisposition();
    if ((disposition != null) && (disposition.equals("ATTACHMENT") || disposition.equals("INLINE")))) {
    String fullpath = filepath+"/" + filename+".csv";               
    File file = new File(fullpath);
    InputStream in = part.getInputStream();
    FileOutputStream fos = new FileOutputStream(file);
    byte[] buf = new byte[part.getSize()];
    int c = 0;
                             while ((c = in.read(buf)) != -1) {
    fos.write(buf, 0, c);
                                       in.close();
                                       fos.close();
                                  } // if (disposition) closing
                             }// inner for loop closing
    /* ----------------------------------------------------Move Message to new folder--------------------------------------------------------------------- */
    if (message.length != 0) {
    folder.copyMessages(message, dFolder);
    folder.setFlags(message, new Flags(Flags.Flag.DELETED), true);
    // Dump out the Flags of the moved messages, to insure that
    // all got deleted
    for (int i = 0; i < message.length; i++)
                                  if (!message.isSet(Flags.Flag.DELETED))
                                       System.out.println("Message # " + message[i] + " not deleted");
                             } //for
    }// if (message.length != 0)
    // System.out.println("*** Message moved to "+tarDir+" Directory ***");
                        }//if loop closing - checking message subject
                   }// if loop closing checking date
    }// outer for() loop closing

  • How to read XML Values using JAVA

    Hi FRNDS,
    I uploaded one XML File in imported Archieves, i have to read the value form XML uisng JAVA code,
    using XSL able to read  like  xsl variable name='TimeZone' select =$linkDoc//...........*
    But using java i have to read the value from XML,is it possible to read the value??
    please give me some sample code.
    regards,
    Raja Sekhar

    But using java i have to read the value from XML,is it possible to read the value??
    Check the below JAVA code from help:
    http://help.sap.com/saphelp_nwpi71/helpdata/en/55/7ef3003fc411d6b1f700508b5d5211/content.htm
    you can ignore the XSLT part and configure only the JAVA code...check if this suits your needs.
    Regards,
    Abhishek.

  • How to forward and reply using java mail?

    Im new to java mail...
    Can anybody give me a detailed examples for
    1. forwarding a mail
    2. Replying to mail
    from javamail?
    thanks in advance
    sandhya

    Detailed? Not necessary. You have to create a new message and send it, that's all. Note that the Message has a reply() method that helps you to do that.

  • How to read SGML files using Java

    I've got a text categorisation test collection called Reuters-21578 for my Information Retrieval project. It is distributed in 22 files. Each of the first 21 files (reut2-000.sgm through reut2-020.sgm) contains 1000 documents, while the last (reut2-021.sgm) contains 578 documents. The files are in SGML format. Each of the 22 files begins with a document type declaration line:
    <!DOCTYPE lewis SYSTEM "lewis.dtd"> The DTD file lewis.dtd is included in the distribution. Following the document type declaration line are individual Reuters articles marked up with SGML tags.
    My questions is how to write a java program to read those 21578 documents or transform them into 21578 seperated text files.

    I guess I missed something. What is Renes link?. The
    parser stuff isn't really what I'm looking for. I'm
    a new at and just learning java and I just want to
    know the easiest way to read a SGML file. Should I
    use a buffered Reader with a Pushback Input Stream?Hang on.....you want to just read the file without intelligently extracting the SGML data contained within and so have no need of a parser?
    Well, in that case, its just text.....so just use BufferedReader or whatever to read the text data. If I understand you correctly, all you really wanted to ask was "how do I read a text file?"

  • Read  the email using java mail api for Imap account which is secured SSL

    hello,
    I am trying read the new mails on my imap account... i am not able to connect to the imap account... could anyone help me out ..
    below is the code
    public class EmailImapGateway implements MessageCountListener{
    private static final long serialVersionUID = 1L;
         private Session session = null;
         private IMAPStore store = null;
         private IMAPFolder folder = null;
         Properties props = new Properties();
         public void ejbCreate() {
         try {
         if (session == null)
              session = Session.getDefaultInstance(props, null);
              if (store == null || !store.isConnected()) {
    String host, name, passwd;
         host = "host";
              name = "user";
              passwd = "passwd";
              String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
              props.setProperty("mail.imap.socketFactory.class", SSL_FACTORY);
              props.setProperty("mail.imap.socketFactory.fallback", "false");
              props.setProperty("mail.imap.socketFactory.port", "888");
              java.security.Security.setProperty( "ssl.SocketFactory.provider", SSL_FACTORY);
              props.put("mail.imap.host", host);
              props.put("mail.imap.port", "888");
              store = (IMAPStore) session.getStore("imap");
              store.connect();
              folder = (IMAPFolder) store.getFolder("Inbox");
              folder.open(Folder.READ_WRITE);
              int t = folder.getUnreadMessageCount();
              System.out.println("getunreadmessagecount is :" + t);
    }catch (Exception e) {
              e.printStackTrace();
         } finally {
              try {
                   folder.close(true);
                   store.close();
              } catch (MessagingException e) {
                   e.printStackTrace();
         public void ejbActivate() throws EJBException, RemoteException {
              // TODO Auto-generated method stub
         public void ejbPassivate() throws EJBException, RemoteException {
              // TODO Auto-generated method stub
         public void ejbRemove() {
              // TODO Auto-generated method stub
         public void messagesAdded(MessageCountEvent arg0) {
              System.out.println("Message is added in inbox");
         public void messagesRemoved(MessageCountEvent arg0) {
              System.out.println("Message is removed from inbox");
    it is not able to connect to my account
    Edited by: bhavna84 on Sep 8, 2008 11:10 PM
    Edited by: bhavna84 on Sep 8, 2008 11:20 PM

    Yes, see my previous post.
    He replied:
    hello
    In your code ur mention IMAP port 888
    but by default its 143 so chk your server configuration for IMAP port no.

  • How to receive HTML email using JAVA Mail API?

    Hello!
    I am developing WEB Mail System. There is a little problem. I am unable to receive mail in HTML format. The mail is being received in only text format currently. What method do i need to use to achieve this functionality currently i am using
    MimeMessage message = mail.getMessage();
    if(message.isMimeType("text/plain")){
    String str_message_body = message.getContent().toString();
    else
    Multipart multipart = (Multipart)message .getContent();
    Kindly advise me regarding that because i am in a state of fix right now and unable to proceed further.
    I will really appreciate a prompt response from you.
    Regards,
    Burhan Ramay.

    HTML is a text format too, so you do
    if(message.isMimeType("text/html")){
    String str_message_body = message.getContent().toString();
    }

  • How to read word files using java

    Reding text files is prity simple. But when i tried to read msword file I could do it.
    Can any one discuss how to do it
    Thanks

    Sorry this is not a reply but in fact i need the solution for that as i am in an urgency of that can you post that to to me if u have got it, I need it for my project

  • How to access MS Exchange Server Mail and download attachment using Java ??

    Hi guys,
    I need to develop a program to access my inbox from MS Exchange Server and also download the attachment using Java language !! Any example code or any site which got tutorial on this ? Thanks !!

    Here is a java file that connects to a users exchange account, reads all messages, and writes the attachment to the file system.
    import java.io.*;
    import java.util.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    public class TestNew {
    public static void main (String args[]) throws Exception {
    // Create empty properties
    Properties props = new Properties();
    // Get session
    Session session = Session.getInstance(props, null);
    // Get the store
    Store store = session.getStore("imap");
    // Connect to store
    store.connect(host, username, password);
    // Get folder
    Folder topFolder = store.getDefaultFolder();
    Folder folder = literature.getFolder("newFolder");
    folder.open(Folder.READ_WRITE);
    Message[] msg = folder.getMessages();
    for(int i = 0; i < msg.length; i++){
    Address[] from = msg.getFrom();
    String subject = msg[i].getSubject();
    Object o = msg[i].getContent();
    if (o instanceof MimeMultipart) { //attachements available?
    MimeMultipart mm = (MimeMultipart) o;
    int mmCount = mm.getCount();
    for (int m = 0; m < mmCount; m++) { // for each part
    Part part = mm.getBodyPart(m);
    String disposition = part.getDisposition();
    if ((disposition != null) && ((disposition.equals(Part.ATTACHMENT) || disposition.equals(Part.INLINE)))) {
    InputStream is = null;
    File tempFile = new File("D:\\TEMP\\mailtest\\" + part.getFileName());
    FileOutputStream fos = null;
    try {
    fos = new FileOutputStream(tempFile);
    is = part.getInputStream();
    int byteCount = 0;
    byte[] bytes = new byte[128];
    while ( (byteCount = is.read(bytes, 0, bytes.length)) > -1) { //use full read() method for GZIPInputStream to be treated correctly
    fos.write(bytes, 0, byteCount);
    finally {
    try {
    if (fos != null)
    fos.close();
    catch (IOException ioe) {}
    try {
    if (is != null)
    is.close();
    catch (IOException ioe) {}
    System.out.println("Content: " + o);
    System.out.println(from[0].toString());
    System.out.println(subject);

  • How to read .cvs(excel file) in mail attachment

    Hi,
    I'm using java mail to read the attachment in mail. The attachment are excel file which is in .csv format.
    I'm able to save the attachment to my hard drive which is in .dat format. i tried to use MimeUtility.decodeText() to decode it back to .csv format but it doesn't work.
    Anyone have any suggestion on how to decode it back to the previous format?
    thanks

    POI

Maybe you are looking for