Save Attachment from exchange server 2010 from oracle using java mail API

Hello,
I want to read email from microsoft exchangeserver 2010 and save attachement into a folder.I created an Java program to import attachments from a exchange server mailbox using "POP3S".It works fine when run as a java application.But when i put this inside Oracle11g R2 using load java and while executing from a procedure it gives an error at parsing message into Multipart
Error at line : Multipart mp = (Multipart)m.getContent();
Error:
Content-Type: multipart/mixed;
boundary="_002_A0C2E09A..................................."
java.lang.ClassCastException
at mailPop3.checkmail(mailPop3:71)
My Java Class is as follows,
import java.io.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Date;
The function i used to check for attachments is given below.
public static boolean hasAttachments(Message m) throws java.io.IOException, MessagingException
Boolean hasAttachments = false;
try
// if it is a plain/html text - no attachements
if (m.isMimeType("text/*"))
return hasAttachments;
else if (m.isMimeType("multipart/alternative"))
return hasAttachments;
else if (m.isMimeType("multipart/*"))
Multipart mp = (Multipart)m.getContent();
if (mp.getCount() > 1)
hasAttachments = true;
return hasAttachments;
catch (Exception e) {
e.printStackTrace();
} finally {
return hasAttachments;
My Java Details as follows
java Version :1.5.0_10
java.vm.specification.version:1.0
java.vm.version :1.5.0_01
java.specification.version:1.5
java.class.version:48.0
Java mail API:javamail-1.4.4
Used Jars:mail.jar
Could someone explain why I am getting this error? What can I do to resolve this error?
Is any other Jar need other than mail.jar?
Any help would be much appreciated.
Regards,
Nisanth

Hai EJP,
Thanks for your reply,
My full java class as follows,
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.Part;
import javax.mail.Multipart;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeMessage;
public class Newmail
public Newmail()
super();
public static int mailPOP3(String phost,
String pusername,
String ppassword)
Folder inbox =null;
Store store =null;
int result = 1;
try
String host=phost;
final String username=pusername;
final String password=ppassword;
System.out.println("Authenticator");
Authenticator auth=new Authenticator()
protected PasswordAuthentication getPasswordAuthentication()
return new PasswordAuthentication(username, password);
System.out.println("Certificate");
String filename="D:\\Certi\\jssecacerts";
String password2 = "changeit";
System.setProperty("javax.net.ssl.trustStore",filename);
System.setProperty("javax.net.ssl.trustStorePassword",password2);
Properties props = System.getProperties();
System.out.println("host-----"+props);
props.setProperty("mail.pop3s.port", "993");
props.setProperty("mail.pop3s.starttls.enable","true");
props.setProperty("mail.pop3s.ssl.trust", "*");
Session session = Session.getInstance(props,auth);
session.setDebug(true);
store = session.getStore("pop3s");
System.out.println("store------"+store);
store.connect(host,username,password);
System.out.println("Connected...");
inbox = store.getDefaultFolder().getFolder("INBOX");
inbox.open(Folder.READ_ONLY);
Message[] msgs = inbox.getMessages();
System.out.println("msgs.length-----"+msgs.length);
result = 0;
int no_of_messages = msgs.length;
for ( int i=0; i < no_of_messages; i++)
System.out.println("msgs.count-----"+i);
System.out.println("Attachment....>"+msgs.getContentType());
Multipart mp = (Multipart)msgs[i].getContent();
System.out.println("Casting Success" + mp.getContentType());
catch(Exception e)
e.printStackTrace();
finally
try
if(inbox!=null)
inbox.close(false);
if(store!=null)
store.close();
return result;
catch(Exception e)
e.printStackTrace();
return result;
Please check it
Regards,
Nisanth

Similar Messages

  • Attach multiple emails to one master email using Java mail API

    Java version: JDK 1.5.0_15
    Hi,
    I am using Java API to send email using our corporate microsoft exchange server. Everything is working fine, now I have a requirement to attach multiple emails to one master email and send.
    Question:
    Using JAVA API is it possible to attach multiple emails to one email?
    Regards,
    Arup

    The beginning of this FAQ entry tells you how to attach one message to another message:
    http://www.oracle.com/technetwork/java/javamail/faq/index.html#forward

  • Upgrade directly from Exchange Server 2010 SP1 to Exchange Server 2010 SP3

    Hi,
    We have current setup with Exchange Server 2010 SP1 ( DAG & CAS Array with WNLB).
    Can we upgrade directly from Exchange Server 2010 SP1 to
    Exchange Server 2010 SP3 . ? 
    Thanks in Advanced.
    Regards,Ali

    Hi Ali,
    Yes, you can. Please upgrade your Exchange 2010 SP1 server roles in the following order: Client Access, Hub Transport, Unified Messaging, Mailbox, Edge Transport. What's more, please note that when you install a Service Pack or update rollup on a server
    that's a DAG member, several services will be stopped during the installation, including all Exchange services and the Windows Cluster service.
    For more information, here is a helpful article for your reference.
    Installing Update Rollups on Database Availability Group Members
    http://technet.microsoft.com/en-us/library/ee861125(v=exchg.141).aspx
    Hope this can be helpful to you.
    Best regards,
    Amy Wang
    TechNet Community Support

  • Migrate from Exchange Server 2011 to Mac OSX Lion Mail Server

    Hi all,
    I'm looking to migrate from Exchange Server 2011 to Mac OSX Lion Mail Server.  I work for a company with roughly 30 employees and they use exchange for mail, contacts and calendars.  We want to take full advantage of OSX Server and to completly get off of exchange.
    What are the best ways to do this?  Are there any tools available to help this process?

    I agree with the points made by Strontium90. If you have any PCs then Apple's mail/contacts/calendar software is a poor choice. Kerio Connect as a mail/contacts/calendar server would not only support Macs but would also do a good job supporting PCs running Outlook.
    If you are going to become a pure Apple site, then you could use just the Apple software and this would be cheaper than using Kerio. For 30 users this might be a suitable solution, however even in a pure Apple environment many people prefer Kerio. For example I find Kerio much more pleasent when dealing with email addresses across multiple domains, email aliases, email group addresses, and so on. Kerio also has built-in email archiving, that is keeping a record of all emails. Kerio also provides a web-browser client for accessing email, calendar and contacts. It is worth noting that as standard Mountain Lion Server no longer includes a webmail feature. While I personally find the Kerio webclient rather ugly it does work.
    There are some annoyances I have with Kerio, firstly they have always charged a 'maintenance' fee for their software. This provided access to software updates, and in the past also provided access to Kerio technical support. Unfortunately they now only let you make two (2) support cases per year for that cost, and you now have to pay extra for any more cases. Also while they added support for EWS (Exchange Web Service) to allow using Outlook 2011 for Mac as a supported email client, they did a poor job of this so that it does not work properly with any other EWS compatible client. This means it will not work in EWS mode with Apple Mail, nor with Outlook for Windows. While there are other ways to connect these other clients, this seems a foolish move and there have been plenty of requests to fix this.
    Apple's Mail client uses EWS to connect to a 'real' MS Exhange server.

  • Exchange Server 2010 mailflow reporting using SCOM 2007

    Hi,
    We are using SCOM 2007R2 in our Organization and we are Monitoring Exchange server 2010.
    We are in need of reports for Mailflow statistics (send and receive)from Exchange server 2010 using SCOM 2007R2.
    Eg: Microsoft Exchange 2010 Server Reports Transport Platform Hourly server Statistics.
    By default reports available in SCOM for Exchange server will not fulfill our requirement.
    Earlier for Exchange server 2007 we are able to fetch the desired reports which is available by default.
    Eg:  Exchange 2007 SMTP Message Received
           Exchange 2007 SMTP Message Sent
    Is there any way to fetch the reports for Exchange server 2010 same as Exchange 2007 reports.
    Thanks

    Hi SonarPal,
    Please look at this post, hope it helps:
    https://social.technet.microsoft.com/Forums/en-US/ffdb8883-226f-410f-abde-bd75c4c88c4a/exchange-transport-reports-no-data?forum=operationsmanagerreporting
    Natalya
    ### If my post helped you, please take a moment to Vote as Helpful and\or Mark as an Answer

  • Exchange server 2010 unable to send internet mails to some domains but receives mail

    Hi all, I have exchange server 2010 deployed and can receive mail with no issues but cant send mails to some external domains. I can send mails to gmail some others. Yahoo! is among the domains that rejects mails originating from my exchange server. Is
    there anyone to assist please?

    You can start here.
    http://www.dummies.com/how-to/content/how-to-get-removed-from-an-email-blacklist.html
    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."

  • Using Java Mail API from Tomcat

    Hello,
    Purely as an academic exercise I have written a JSP page which, upon being requested from the client's browser, should send me a default email using Java Mail Api.
    here is the code :
    import java.util.*;
    import java.io.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    public class TestMail {
        static String msgText1 = "success this time 12";
        static String msgText2 = "This is the text in the message attachment.";
        public String sendIt() {
            String to = "<my email";
            String from = "<anything>";
            String host = "<my ip address of smtp server>";
            boolean debug = false;
            Properties props = new Properties();
            props.put("mail.smtp.host", host);
            Session session = Session.getInstance(props, null);
    .....The code works fine as a stand alone app but when called from JSP page it hangs on the Session.getInstance line. I can only guess that this might be a security issue with the container not allowing access to the smtp server ?
    Can anyone give me a clue ???

    Your Tomcat log files should spell out the problem for you.
    My Tomcat installation does not come with the Java Mail API. I had to add the mail and activation jar files to the server/common.lib directory (or the server's shared/lib or the WEB-INF/lib of your application.)
    HTH.

  • How to delete message from the fodler of  AOL account using Java mail

    Hello All,
    I am using Java MAil API in my application, i want to delete message from AOL account's folder,
    when i set the folder as "Recently Deleted" or "Trash" , i get an exception as "folder does not exist".
    when i tested , some times mail is moving into Recently Deleted folder, but not every time.
    this is happening in both the interface as AOl Interface or my application.
    when i use folder.close(true) after setting the flag of message as DELETED. it completely remove the message from the acount.
    but i want to let the message be remained in the Recently Deleted folder. what should i do.
    i dont want to remove the message completely from the account.I am using IMAP also.

    You'll need to figure out what the real name of the "Recently Deleted" folder is on the AOL IMAP server
    (assuming it's a real folder and not some sort of "virtual" folder), then copy the message into that folder.
    See the folderlist.java demo program as a way to explore the names of all the folders on the server.

  • Using Java mail API from JSPDynPage

    Hi Experts,
    I am working on a Portal Assignment that requiresto sent work flow mails on the basis of error conditions.
    Can u please suggest if at all I can use Java Mail APIs from JSP page within the JSP DYN Page Framework.
    If at all Java Mail can be used could u please suugest some help docs on the same.
    Thanks for the help.
    Manab C Ghosh
    EP Consultant
    Kolkata INDIA
    +919830603327

    Hi Experts,
    Thanks for all the responses to my Mail question(mailing from JSPDynPage).
    I have found the solution.
    Here is how I have got the things: (pls note there are other solns)
    Using Java Mail APIs;
    Create a Java file in the scr.core / src.api
    MailSender.java
    * Created on Jul 21, 2005
    * To change the template for this generated file go to
    * Window>Preferences>Java>Code Generation>Code and Comments
    package com.mailsend.test;
    import java.util.Date;
    import java.util.Properties;
    import javax.mail.Message;
    import javax.mail.MessagingException;
    import javax.mail.Multipart;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeBodyPart;
    import javax.mail.internet.MimeMessage;
    import javax.mail.internet.MimeMultipart;
    * Edited on Jul 24, 2005
    * @author Manab C Ghosh
    public class MailSender {
         public String sendMessage(){
            String msg ="Hello mail Test";
            String smtpServer ="mySMTPServer";
            String smtpSender = "senderemailaddress";
            String smtpRecipient="receipientemailaddress";
            String stBody =  msg ;
            //String stDate = new Date().toString() ;
            String stSubject = "Mail Test ";
            Send(     smtpServer,          //SMTPServer
                      smtpSender,          //Sender
                      smtpRecipient,     //Recipient
                      stSubject,          //Subject
                      stBody               //Body
                        );               //Attachments                    
         return "Mail Success";
    public static void Send(String SMTPServer,
                                  String From,
                                  String To,
                                  String Subject,
                                  String msgText1
            // Error status;
            int ErrorStatus = 0;
            // create some properties and get the default Session
            Properties props = System.getProperties();
            props.put("mail.smtp.host", SMTPServer);
            Session session = Session.getDefaultInstance(props, null);     
            try {
                 // create a message
                 MimeMessage msg = new MimeMessage(session);
                 msg.setFrom(new InternetAddress(From));
                 InternetAddress[] address = {new InternetAddress(To)};
                 msg.setRecipients(Message.RecipientType.TO, address);
                 msg.setSubject(Subject);
                 // create and fill the first message part
                 MimeBodyPart mbp1 = new MimeBodyPart();
                 mbp1.setText(msgText1);
                 // create the Multipart and its parts to it
                 Multipart mp = new MimeMultipart();
                 mp.addBodyPart(mbp1);
                 //mp.addBodyPart(mbp2);
                 // add the Multipart to the message
                 msg.setContent(mp);
                 // set the Date: header
                 msg.setSentDate(new Date());
                 // send the message
                 Transport.send(msg);
            } catch (MessagingException mex) {
    Call this file from the JSP page (which is set at JSPDynPage controller)
    one important thing-----
    Create a dir under PORTAL-INF and import the following jars-- activation.jar, mail.jar,imap.jar,smtp.jar, mailapi.jar.
    This works..
    Thanks once again to the Experts.
    happy mailing
    Manab Ghosh.
    INDIA (+919830603327)

  • How can i access gmail's smtp server using java mail api

    i m using java mail api to access gmails pop and smtp service to receive and send mail from ur gmail account. I m able to access gmails pop server using the ssl and port 995 , but i can not use its smtp server to which i m connecting using ssl on 465 port. It requires authentication code.
    if anybody can help me in this regard i m thnkful to him/her.
    thnks in advance.
    jogin desai

    Here's an example of using SSL + Authentication
    http://onesearch.sun.com/search/onesearch/index.jsp?qt=ssl+authentication&subCat=siteforumid%3Ajava43&site=dev&dftab=siteforumid%3Ajava43&chooseCat=javaall&col=developer-forums

  • How to do SAVE AS DRAFT using java mail api

    Hello,
    I want to know how to do SAVE AS DRAFT using Java mail Api.
    thanks

    Hello,
    I want to know how to do SAVE AS DRAFT using Java
    mail Api.
    thanksI don't think you can. That sounds like a feature of a mail client app itself. The Java mail API is for when you're ready to actually send the thing. Saving drafts is storing them somewhere like you would any other data; nothing to do with the mail API.

  • Migrate from Exchange Server 2010 sp3 to 2013 sp1

    I have one Exchange Server 2010 SP3 server (300 mailboxes) installed on Windows Server 2008 R2 SP1 with three major roles on it (CAS, MB and HT) - typical installation. Edge Transport server is not installed thus for controlling of mail flow
    Symantec Messaging Gateway Virtual Appliance is used as Smart Host. UM server is not installed either. I set up test domain environment where I installed one domain controller (Windows Server 2008 R2 SP1) and one Exchange Server 2010 SP3 (Windows
    Server 2008 R2 SP1) at first place and yesterday I did everything necessary to install Exchange Server 2013 SP1 on new test virtual server running Windows Server 2012 R2 which I successfully did.
    Now in test domain I have two Exchange Servers (2010 SP3 and 2013 SP1). Is there any 100% reliable documentation with all actions that had to be taken in order to successfully migrate Exchange Server 2010 SP3 to 2013 SP1? I would want to know what
    needs to be done not only for my scenario but also for other scenarios (DAG, CAS array, Edge, UM, multiple HT servers . . .) since I am interested in digging deep into Exchange Server 2013.
     

    Hi BoxiKG,
    In addition to the above mentioned, and this for your reference:
    Upgrade from Exchange 2010 to Exchange 2013
    http://technet.microsoft.com/en-us/library/jj898583(v=exchg.150).aspx
    Best regards,
    Eric

  • Recover mailbox from Exchange server 2010 information store to exchange server 2013

    I have a big issue. I have a correct exchange server 2010 where the active directory is corrupt but the information store is good.
    I would like to recover a couple of mailboxes to an exchange server 2013.
    Can anyone give me a detailed walk through of how I can accomplish this?
    Thank in advance

    Well if your AD is messed up that leaves you in a jam for sure because;
    1. Database portability ONLY works within the same organization, so you cannot just install a new 2010 server in a completely different forest and then move the DB in hopes that DB portability will work.
    2. As Ed said you should build a new Exchange 2010 server and use portability but it has to be in the same organization.
    3. Here is a good article on how to accomplish
    http://exchangeserverpro.com/exchange-2010-database-portability-disaster-recovery/
    4. Now if you by chance have an AD backup before it went south you could build a separate network with same names etc just keep it isolated from the production server and then restore AD to that environment and you could then use DB portability.
    That said if you don't have any other machines to work with then you are in a bit of a pickle and will have to use a 3rd party product to get to that data within the 2010 DB.   We make a product that can do this (DigiScope), however if you don't
    have any budget to handle its a non-issue.
    The only other thing you could consider is to restore your AD from a previous point in time, however BE VERY CAREFUL if you consider this since it could cause more issues then you have now.
    BTW if you AD is messed up, where are you putting this new 2013 server?
    Search, Recover, & Extract Mailboxes, Folders, & Email Items from Offline Exchange Mailbox and Public Folder EDB's and Live Exchange Servers or Import/Migrate direct from Offline EDB to Any Production Exchange Server, even cross version i.e. 2003 -->
    2007 --> 2010 --> 2013 with Lucid8's
    DigiScope

  • Migration from Exchange server 2010 to Exchange server 2013

    Hi All,
    We have migrate Exchange Server 2010 to Exchange Server 2013. When I turned off my Exchange Server 2010, Outlook is not able to connect through Exchange 2013. It's prompting for user name and password again and again and nothing would happen
    after provide user name and password. So, we are not able to uninstall exchange 2010 from old server.

    Run these commands and post the update.
    Get-WebservicesVirtualDirectory -Server E2K13SERVER |Fl internalURL,ExternalURL
    Get-OWAVirtualDirectory -Server E2K13SERVER | Fl internalUrl,ExternalURL
    Get-ClientAccessServer E2K13SERVER | Fl AutodiscoverServiceInternalUri
    Cheers,
    Gulab Prasad
    Technology Consultant
    Blog:
    http://www.exchangeranger.com    Twitter:
      LinkedIn:
       Check out CodeTwo’s tools for Exchange admins
    Note: Posts are provided “AS IS” without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

  • Can I install the Exchange Server 2010 from my SBS2011 onto a sceond server, whilst still keeping the SBS2011 ?

    Hi,
    My customer currently has an HP Proliant ML350p G8 running SBS2011.
    What they want to do is install the whole Exchange Server 2010 onto a second server which is running Server 2008 R2 Standard which is on the domain as an additional Domain Controller.
    Is this possible ??
    Many thanks
    Alan Skinner

    Running Exchange Server on a DC is supported. Here are some issues you can get:
    http://support.microsoft.com/kb/940845
    Please mark as helpful if you find my contribution useful or as an answer if it does answer your question. That will encourage me - and others - to take time out to help you. Thank you! Off2work

Maybe you are looking for

  • How do I import Edge files into my Wordpress site

    New to edge.  Need to know how to incorporate the finished edge file into my WordPress site.  Specifically I want to create an animated banner.

  • Toshiba EXCITE Pro - WIFI connection. Authentication failed after update

    Hello. Just received this Tablet. Everything seemed ok while updating to the latest version (did that first to solve the heat problems). After the last update *i lost my WIfi connection. Authentication failed* (didnt change something - was connecting

  • I-tunes and Quicktime  make a fatal error on Vista ?!

    Hi i'm italian ... i don't write a good english but i try too explain my problem... i have a laptop HP pavilion dv6000 with windows vista... i 2 week ago buy a ipod touch 2g ... i try to install itunes ... i download it from apple.it. during the inst

  • Itunes folder location problem

    I recently consolidated my library to an external drive but every time I restart iTunes (after a reboot) the default location reverts to local harddrive on my Macbook. Did I consolidate incorrectly? How do I get the music folder location to stay poin

  • Sales Document

    Hai    Can Anybody tell me what is the description of the Standard Report of 1.list of Billing Document 2 list of sales orders Actually what those reports says what is the use of it?