Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JavaMail problem in viewing the mail's content using javamail

Have Programming Question? Ask it here!
 
 
 


Karan Gurnani
problem in viewing the mail's content using javamail
0 Answer(s)      2 years and 3 months ago
Posted in : JavaMail


i'm using the following code to view a mail in a javamail application problem i'm facing is if there are any attachments of .txt format they are also displayed as if they are body of the mail. Secondly in some mails i'm getting the following Exception :

java.lang.ClassCastException: java.lang.String cannot be cast to javax.mail.Multipart

also pls guide me how to extract the body and attachments of the mail

Code which i've used is :

**package desktopapplication1; import javax.mail.*; import java.io.*; import java.util.Properties.*; import javax.swing.*; import javax.swing.table.*; import javax.mail.internet.*; import java.util.*; import desktopapplication1.Fetchmail; import javax.mail.Multipart.*; import desktopapplication1.Start.*; import javax.activation.DataHandler; /** * * @author Karan */ public class Viewmail { String subject; List<String> list=new ArrayList<String>(); String st=null; /*Viewmail(String name) { this.subject=name; showmail(subject); }*/ public List showmail(String name) { String user=Start.getUsername(st); Properties props = System.getProperties(); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.transport.protocol", "smtp"); Session mailSession = Session.getDefaultInstance(props,null); File file=new File("mails/"+user+"/"+Fetchmail.replacename(name)+".eml"); System.out.println(file.getPath()); String files; try{ files=file.getPath(); File emlFile = new File(files); InputStream source = new FileInputStream(emlFile); MimeMessage message = new MimeMessage(mailSession, source); Date date = message.getSentDate();

                String ssfrom = InternetAddress.toString(message.getFrom());
                String subj = message.getSubject();
                String sdate=String.valueOf(date);
                StringBuilder build=new StringBuilder();
                String body=new String();
                String body2=new String();
                InputStream stream = message.getInputStream();
                while(stream.available()!= 0) {

                     build.append((char)stream.read());
                }
                 if (message.getContentType().equals("text/html")||message.getContentType().equals("text/plain"))
                    { body2=(String)message.getContent();
                    }
                body=build.toString();
                 list.add(ssfrom);
                list.add(subj);
                list.add(sdate);
                //list.add(body);
                Object object=message.getContent();
                Multipart mp=(Multipart)object;
               Part[] pa=new Part[mp.getCount()];
               Part p=null;
                for(int j=0;j<mp.getCount();j++)
               {    p=mp.getBodyPart(j);
                    p.getContentType();
                    String disposition=p.getDisposition();
                    if(p.getContentType().startsWith("text/plain") ||
                    p.getContentType().startsWith("text/html"))
                    { body2=(String)p.getContent();

                    }
                    if(disposition!=null&&(disposition.equals(BodyPart.ATTACHMENT)))
                    {   System.out.println("there is an attachment");
                        DataHandler handler=p.getDataHandler();
                        System.out.println("file name: "+handler.getName());
                    }
                }
                list.add(body2);

         }//end of try
       catch (Exception e)
        {System.out.println(e);
        }//end of catch

return list; }//end of show }**


Advertisement
View Answers

Related Tutorials/Questions & Answers:
problem in viewing the mail's content using javamail
problem in viewing the mail's content using javamail  i'm using the following code to view a mail in a javamail application problem i'm facing... as if they are body of the mail. Secondly in some mails i'm getting the following Exception
send without authentication mail using java - JavaMail
send without authentication mail using java  Dear All, I am tring to send simple mail without authentication using java. is it possible, could...(Message.RecipientType.TO, "to mail id"); msg.setSubject("JavaMail hello world
Advertisements
extract content from javamail - JavaMail
extract content from javamail  Hi, I currently try the example(Read Multipart mail using Java Mail) on Javamail from the site to receive the e-mail. Then If I going to extract text the message content. What can I do
values of the "from address & to addresses" while sending a mail to localhost using javamail
values of the "from address & to addresses" while sending a mail to localhost using javamail  Hi, I verified javamail tutorial which is mentioned in JavaMail in ur website.I tried 1st program for sending the Mail.It's
Java Mail - JavaMail
Java Mail  how to email using Java mail or automatic generated mail???  Hi Friend, Please visit the following link: http://www.roseindia.net/javamail/ Hope that it will be helpful for you. Thanks
java mail api - JavaMail
java mail api  Hi, Pls give me the detailed information on how... in the code..   Hi friend, For solving the problem remember some points : 1.Download the Apache Mail server (James) http://james.apache.org
java mail error - JavaMail
java mail error  how to rceive emails using java mail api  Hi Friend, We can use Java Mail APIs to send and receive mails in Java.... Please visit the following link to know more about use of Java Mail API. http
How i can send mail by using jsp.............. - JavaMail
How i can send mail by using JSP  Hi, will you please tell me how i can send mail by using jsp. Tell me in detail. Thanks!  Example and JSP... to create a send mail program using JSP.JSP Send Mail Program Resources:-http
JAVA MAIL - JavaMail
application using JAVA MAIL API.  Hi Friend, Please explain us what code you are using so that we can rectify the problem. If you are getting the Email...JAVA MAIL  Hi! I am doing project called "E-mail Client
JAVA MAIl - JavaMail
JAVA MAIl  Hi, I am trying to send a mail using java mail api. But I am getting following error: javax.mail.SendFailedException: Sending failed...: http://www.roseindia.net/javamail/ Hope that it will be helpful for you
java mail - JavaMail
java mail  how to send a mail without authentication in java ?  Hi Friend, Please visit the following link: http://www.roseindia.net/javamail/ Hope that it will be helpful for you. Thanks
sent mail code - JavaMail
sent mail code  hi i have done a project in my final year.acually... a folder like SENT MAILS.so i need a sugestte code to that.pls send to my mail... . This link contains examples over the Java Mail API.. http://www.roseindia.net
Java Mail exception - JavaMail
Java Mail exception  Hi! I am developing E-mail Client (GMAIL) program using JSP technology. Till now i dont have any problem. From last 3 days while i am connecting to the Gmail, I am getting the following exception... Whats
problem in record viewing in jsp - JSP-Servlet
problem in record viewing in jsp  hai i send the code can you please find where is the problem it is not showing any error but i cannot able to view... and servlet and back end mysql actually what is my problem is i have to everytime
Problem in record viewing in jsp - JSP-Servlet
Problem in record viewing in jsp  hai i have developed the application using jsp,servlets in eclipse ide i have to insert,delete,update and view . no problem all are working but in view part alone some problem i dont know what
Sending mail - JavaMail
Sending mail  Need a simple example of sending mail in Java  Hi,To send email you need a local mail server such as apache james. You first download apache james mail server and install on the local network.Then create
Java Mail API - JavaMail
account using java mail api... i got code from our roseindia.net i.e....Java Mail API  Hi! I wish u advanced happy new year to all of ur... exception... Please solve my problem... Thanks in advance... Exception
JAVA Mail - JavaMail
JAVA Mail  Hi! I am trying to send the mail using SMTP of gmail. program was compiled successfully. when i am trying to execute that program it is showing error --- Must issue STARTTLS command first... How to avoid
java mail - JavaMail
java mail  HI! I am developing email client. Using IMAP i am displaying all the messages which are in "INBOX". I want to know how to access remining folders such as "sent", "draft" and others..... Thanks in advance
mail problem
mail problem  Sir, I tried ur send mail example but it giveng...; <title>Mail API</title> </head> <body><table...;Mail API</h1> <tr>
Mail from JSP with SMTP - JavaMail
Mail from JSP with SMTP  Hi, Can any one pls guide me how to send mail from JSp page by using SMTP IP address. Regards...,Britto.M  Hi Friend, Please visit the following link: http://www.roseindia.net/mail
what is java mail API - JavaMail
what is java mail API  Please tell me in detail what is java mail API
gmail access using javamail API
gmail access using javamail API  how to coonect to gmail using java mail API ?  Hi Friend, Please visit the following link: http://www.roseindia.net/javamail/ Hope that it will be helpful for you. Thanks   
problem in getting mail exchange records(MX) using DNS in java
problem in getting mail exchange records(MX) using DNS in java  Hi, jsp file: <%@page import="javax.naming.NamingEnumeration"%> <...) at java.lang.Thread.run(Thread.java:619) Note : I am using glassfish v3. above code works fine
problem in getting mail exchange records(MX) using DNS (glassfish(struts2))
problem in getting mail exchange records(MX) using DNS (glassfish(struts2))  Hi, dummy.jsp <%@page import="javax.naming.Context"%> <%@page import="java.util.Hashtable"%> <%@page import
sending mail using jsp
sending mail using jsp  please give me the detailed procedure and code for sending mail through jsp program   Please visit the following...://www.roseindia.net/javamail
problem getting password - JavaMail
problem getting password  hi i am trying to get password but igot following error Error sending mail:javax.mail.MessagingException: Could not connect to SMTP host: 192.168.10.14, port: 25;nested exception
email problem - JavaMail
email problem  hi,i want to write a code for sending a mail to a company employees having strength more than 1000.I had fetched the mail ids from database.I want to send mail to employee with mail id in 'TO' column.To column
get from address using javamail api?
get from address using javamail api?  i want to get from address of particular mail using the javamail api? actually i had done it in one .jsp file using the particular mail number. message[messageno].getFrom()[0
iphone mail sending problem
iphone mail sending problem  Hi, I'm receiving the following error ... while sending mail in my iphone application Terminating app due to uncaught... it done myself... actually in my send mail code i have predefined the mailto id
send the mail with attachment problem - Struts
send the mail with attachment problem  Hi friends, i am using... mail server properties.setProperty("mail.smtp.host", host... InternetAddress(to)); message.setSubject("JavaMail Attachment
Forwarding Messages using Java Mail
using javamail api. there is no method to forward a mail from one user to another... Forwarding Messages using Java Mail   ... and get message content then send its for another user. Java code given below
How to read yahoo mail using java mail api - WebSevices
How to read yahoo mail using java mail api  Hi there .... i wanted to know how to read mail from yahoo using pure java code. Is there any one who can...://www.roseindia.net/javamail/ Hope that it will be helpful for you. Thanks
i have problem in that program - JavaMail
i have problem in that program  1. Write a multi-threaded Java program to print all numbers below 100,000 that are both prime and fibonacci number... a simple OPAC system for library using even-driven and concurrent programming
java mail send using setText()
); Here am using set Text() method to send mail content in html format. if i use set Text() method mail content is display same structure what i wrote the code...java mail send using setText()  Hai , Am newly mail send portion
send mail using JavaScript
send mail using JavaScript  How can we send mail using JavaScript?   Hi friends, You can not send email directly using JavaScript. But you can use JavaScript to execute a client side email program send the email using
send mail using smtp in java
send mail using smtp in java  How to send mail using smtp in java?   Sending mail in JSP - SMTP
Read attachment message using Java Mail
a Attachment message using javamail api. Java Mail API provides classes to send multiple... Read attachment message using Java Mail   ...;mail Return-Path: <test@localhost> Delivered-To: <
when sending the mail from java I am getting the below error - JavaMail
when sending the mail from java I am getting the below error   when sending the mail from java I am getting the below error : Exception... not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:/mail/mail.jar,file
Read Multipart mail using Java Mail
message using javamail api. When we read a multipart mail firstly create... Read Multipart mail using Java Mail   ... bodyPart content using getContent() method. ReadMultipartMail.java
Sending message using Java Mail
Sending message using Java Mail   ... using javamail api. A client create new message by using Message subclass. It sets attributes like recipient address and the subject, and inserts the content
i have problem in that program sir - JavaMail
i have problem in that program sir  1.Develop multi-threaded echo server and a corresponding GUI client in Java
mail
mail  I wrote a program to send mail using smtp. But there is an error message " could not connect to smtp.gmail.com port 465. what is the problem how can i solve it ...   Please visit the following link: Java Mail API
mail
mail  how to send mail using jsp   Please visit the following links: JSP Send Mail Java Mail Tutorials
Handle EML(Electronic mail) file with Java Mail
eml(Electronic mail) file using javamail api. eml is a simple email, all eml... Handle EML(Electronic mail) file with Java Mail...-Version: 1.0 Content-Type: text/plain; charset=us
Mailing - JavaMail
Mailing  Dear Friends, How can i send mails to yahoo,gmail,other mail servers using javamail using a jsp file. Please help me
Using Single Quote in Reciepient mail Id.
Using Single Quote in Reciepient mail Id.  Hi, Is it possible to send a mail to a Mail Account having singlequote (Ex: prasad'g@gmail.com) by using JAVA Mail API. Could you please give me the clarification.......   Hi
Reading message using Java Mail
Reading message using Java Mail       This Example shows you how to read message using javamail.... store.connect(host, user, password) Connect to the current host using
Transfer or labeling mail using the imap in php
Transfer or labeling mail using the imap in php  Hello all , please suggest me to transfer and labeling mail using imap in php.my script is break after processing around 8000 of 41,000 for labeling .please suggest me some way
Unable to send mail using php script
Unable to send mail using php script  Hello i am trying to send mail using mail function.But the message is never sent. I have installed a free smtp... settings are [mail function] ; For Win32 only. SMTP = localhost smtp_port = 25
Advertisements
 

 

 

DMCA.com