Good morning to all.
I'm trying to use javamail for the first time. After the propper Javamail f.A.Q and documentation reading i create a jsp file with a simple email client which is working good except one thing. Every email that i send from my different varius email accounts is a multipart one and contains tow parts with the same message body .
Even a simple "test" word from outlook,gmail and hotmail is been send in two parts with the same body.
So in my code i have this java bean which gets the msg and returns the body
public final String getPart(Part p) throws Exception { if(p.isMimeType("text/html") || p.isMimeType("text/plain")){ if(!body.equals((String)p.getContent())){ logger.info("---- text/plain Message Part ----"); body = body + (String)p.getContent();} }else if(p.isMimeType("multipart/*")){ logger.info("------- MultiPart Message -------"); Multipart mp = (Multipart)p.getContent(); level++; int count = mp.getCount(); for (int i = 0; i < count; i++) getPart(mp.getBodyPart(i)); level--; }else if(p.isMimeType("message/rfc822")){ logger.info("--------- Nested Message --------"); level++; getPart((Part)p.getContent()); level--; }else{ Object o = p.getContent(); if (o instanceof String) { logger.info("--------- Simple String ---------"); body += (String)o; } else if (o instanceof InputStream) { logger.info("---------- Inputstream ----------"); InputStream is = (InputStream)o; int c; while ((c = is.read()) != -1) body += c; } else { logger.info("---------- Uknown Type ----------"); body += o.toString(); } } String filename = p.getFileName(); String disp = p.getDisposition(); if (level != 0 && disp != null ) { if(disp.equalsIgnoreCase(Part.ATTACHMENT)){ if (filename == null) filename = ""; try { File f = new File(filename); if (!f.exists()){ ((MimeBodyPart)p).saveFile(f); } body += "Επισυναπτόμενο: <a href=\"" + f.getAbsolutePath() + "\">" + filename + "</a>"; } catch (IOException ex) { logger.error("Failed to save attachment: " + ex); } } } return body; }
So my problem is that every email is been showing two times without any exception. Any ideas will be appreciated.
Thanks in advance..