Order, Paginate and List  emails in JavaMail API

Am able to sendm and retrieve emails in java using JavaMail API but am having a problem. I would like to sort emails by date, subject, sender etc and also display only a subset of emails using pagination.
            Message[] msgs = folder.getMessages();
            FetchProfile fp = new FetchProfile();
            fp.add(FetchProfile.Item.ENVELOPE);
            folder.fetch(msgs, fp);The function folder.getMessages(); can take 2 arguments (from_index,to_index), but this is according to the way mail server will transalate. POP server will arrange by date while IMAP is unordered. I would like to order the mails then fetch the getMessages(from_index,to_index).
Another posible way am seeing is fetching all mesages using getMessages() put them in a temporary storage(eg. vector or list), order them and then fetch only the page i want. But this could be very costly in terms of processing resources, which makes me believe there is a better approach and it seems i cant find it.
Can somenone please advice me on what to do. I will be very greatful.
Edited by: kagara on Aug 27, 2008 12:27 PM

With POP3 you have no choice but to download the messages and sort them in the client.
The POP3 protocol simply doesn't provide a "sort" option.
With IMAP, some IMAP servers support a "SORT" extension, although JavaMail doesn't
support it yet.

Similar Messages

  • Email without javamail api

    Is there any way to send email with java without using the javamail api
    regards
    fightspam

    Try this
    import java.net.*;
    import java.util.*;
    import java.io.*;
    public class email
        private static final String host="smtp.smtphost.co.uk";
        private static final String to="[email protected]";
        private static final String subject="autogenerated message";
        static void send(String message)
            try
                System.getProperties().put("mail.host",host);
                URL url = new URL("mailto:" + to);
                URLConnection connection = url.openConnection();
                connection.setDoInput(false);
                connection.setDoOutput(true);
                connection.connect();
                PrintWriter out = new PrintWriter(new OutputStreamWriter(connection.getOutputStream()));
                out.print("From: <"+InetAddress.getLocalHost().getHostName()+">\n");
                out.print("To: "+to+"\n");
                out.print("Subject: "+subject+"\n");
                out.print("\n");
                out.print(message);
                out.close();
            catch (Exception e)
        public static void main(String[] args)
            for(int i=0;i<10;i++)
                send("this is a test message");
    }

  • Issues with signing an Email with JavaMail Api and BouncyCastle provider

    Hi everyone
    I am getting this strange error which I can not figure out what is it about.
    Exception in thread "main" java.lang.NoSuchFieldError: id_alg_CMS3DESwrap
         at org.bouncycastle.cms.CMSEnvelopedGenerator.<clinit>(Unknown Source)
         at org.bouncycastle.mail.smime.SMIMEGenerator.<clinit>(Unknown Source)
         at net.suberic.crypto.bouncycastle.SMIMEEncryptionUtils.signBodyPart(SMIMEEncryptionUtils.java:215)
         at net.suberic.crypto.bouncycastle.SMIMEEncryptionUtils.signMessage(SMIMEEncryptionUtils.java:257)
         at cityLocator.SignMessage.main(SignMessage.java:53)
    This is my code :
    public static void main(String[] argv) {
    try {
    Session mailSession = Session.getDefaultInstance(System.getProperties());
    MimeMessage newMessage = new MimeMessage(mailSession);
    String content = "This is a signed message. \n\nYou know it has actually been sent by this fictional person.\n\nImagine if you received an email claiming to be from this nonexistent person, but was actually from some other made-up persona? That would be bad.\n\n";
    newMessage.setContent(content, "text/plain");
    newMessage.setFrom();
    newMessage.setRecipients(Message.RecipientType.TO, "[email protected]");
    newMessage.setSubject("This one is signed.");
    newMessage.saveChanges();
    // get our signer(s)
    EncryptionUtils smimeUtils = EncryptionManager.getEncryptionUtils(EncryptionManager.SMIME);
    // load the associated store(s)
    char[] smimePw = new String("********").toCharArray();
    EncryptionKeyManager smimeKeyMgr = smimeUtils.createKeyManager();
    smimeKeyMgr.loadPrivateKeystore(new FileInputStream(new File("Dmcave1.pfx")), smimePw);
    smimeKeyMgr.loadPublicKeystore(new FileInputStream(new File("Dmcave1.pfx")), smimePw);
    java.security.Key smimeKey = smimeKeyMgr.getPrivateKey("***************", smimePw2);
    MimeMessage smimeSignedMsg = smimeUtils.signMessage(mailSession, newMessage, smimeKey);
    Error is here--> smimeSignedMsg.writeTo(new com.sun.mail.util.CRLFOutputStream(new FileOutputStream(new File("smimeSigned.msg"))));
    MimeMessage pgpSignedMsg = pgpUtils.signMessage(mailSession, newMessage, pgpKey);
    } catch (Exception e) {
    e.printStackTrace();
    Any ideas or helps would be appreciated

    Hi everyone
    I am getting this strange error which I can not figure out what is it about.
    Exception in thread "main" java.lang.NoSuchFieldError: id_alg_CMS3DESwrap
         at org.bouncycastle.cms.CMSEnvelopedGenerator.<clinit>(Unknown Source)
         at org.bouncycastle.mail.smime.SMIMEGenerator.<clinit>(Unknown Source)
         at net.suberic.crypto.bouncycastle.SMIMEEncryptionUtils.signBodyPart(SMIMEEncryptionUtils.java:215)
         at net.suberic.crypto.bouncycastle.SMIMEEncryptionUtils.signMessage(SMIMEEncryptionUtils.java:257)
         at cityLocator.SignMessage.main(SignMessage.java:53)
    This is my code :
    public static void main(String[] argv) {
    try {
    Session mailSession = Session.getDefaultInstance(System.getProperties());
    MimeMessage newMessage = new MimeMessage(mailSession);
    String content = "This is a signed message. \n\nYou know it has actually been sent by this fictional person.\n\nImagine if you received an email claiming to be from this nonexistent person, but was actually from some other made-up persona? That would be bad.\n\n";
    newMessage.setContent(content, "text/plain");
    newMessage.setFrom();
    newMessage.setRecipients(Message.RecipientType.TO, "[email protected]");
    newMessage.setSubject("This one is signed.");
    newMessage.saveChanges();
    // get our signer(s)
    EncryptionUtils smimeUtils = EncryptionManager.getEncryptionUtils(EncryptionManager.SMIME);
    // load the associated store(s)
    char[] smimePw = new String("********").toCharArray();
    EncryptionKeyManager smimeKeyMgr = smimeUtils.createKeyManager();
    smimeKeyMgr.loadPrivateKeystore(new FileInputStream(new File("Dmcave1.pfx")), smimePw);
    smimeKeyMgr.loadPublicKeystore(new FileInputStream(new File("Dmcave1.pfx")), smimePw);
    java.security.Key smimeKey = smimeKeyMgr.getPrivateKey("***************", smimePw2);
    MimeMessage smimeSignedMsg = smimeUtils.signMessage(mailSession, newMessage, smimeKey);
    Error is here--> smimeSignedMsg.writeTo(new com.sun.mail.util.CRLFOutputStream(new FileOutputStream(new File("smimeSigned.msg"))));
    MimeMessage pgpSignedMsg = pgpUtils.signMessage(mailSession, newMessage, pgpKey);
    } catch (Exception e) {
    e.printStackTrace();
    Any ideas or helps would be appreciated

  • X.400 instead of SMTP Protocol and Javamail API

    We have developed a workflow application on Domino 5.0.7. The SmartHost is "MS Exchange Server", because the application will only be accessed by browsers, we are using javaagent to send the email notifications. Due to some domain restrictions on MS Exhchange servers we have implemented Javamail API on the domino server, and it worked fine (I mean the messages were received by the Exchange Clients, using the SMTP addresses like [email protected]). As we dont have available SMTP addresses for all end users in the company we need to use the X.400 addresses. Is there anyone, can help guide about either the avaiability of any X.400 javamail api, or how to use mapi etc? I know it is little bit challenging, but we are struck. thanks

    Currently, the latest version of the JavaMail 1.2 API, X.400 transport protocol is not supported yet. Only the transport SMTP - a message Transport protocol, for sending messages to a server, is supported.
    Allen Lai
    SUN Developer Technical Support

  • EWS Managed API: Email sender name incorrect if loading properties of multiple emails and several emails have same email address (but different names)

    Hi,
    I have an issue using the Exchange Web Services Managed API. I'm essentially implementing an 'inbox', and am essentially using two calls:
    folder.FindItems(filter, view) with the view set up with the 'idonly' property.
    The returns a 'FindItemResults<>' object containing a set of items.
    And then calling service.LoadPropertiesForItems(items, props), where the props contains all 'first class properties', which includes the sender details.
    Now, the inbox contains several emails from the same email address but with different displaynames.
    E.g. There may be one email from "Bob <[email protected]>" and another email from "Alice <[email protected]>" and another email from "Charlie <[email protected]>" etc.
    The issue is that in the information that EWS returns from the call to LoadPropertiesForItems, every email ends up with the same sender name (from the first one in the list)!
    i.e. When I enumerate through the returned items, the item.Sender.Name will always be"Bob" for every email where Sender.Address is [email protected] 
    I have debugged this with a http sniffer just to ensure that it really is the EWS coming back with this information rather than anything in the managed layer.
    Is this a known issue? How can I work around this (without querying every single email for the sender name individually, as that would be too slow)?
    Thanks

    Hi Venkat,
    Thanks for the reply.
    The scenario is that the client receives emails from a (3rd-party) automated system. The email address from this automated system is always "noreply@<blah.com>", while the display name is used to differentiate the actual sender.
    I suspect that this kind of system will likely become more widely used, and so for us will increase in priority (obviously its a priority for our client already)!
    Just for the record, if this is a known issue do you have a bug number or equivalent for it? (I tried to search but couldn't locate it).

  • JavaMail and Valid Email Address

    Hello All,
    I am using JavaMail API to send thousands of emails every day through my application running on J2EE application server...
    But what i really want to do is, how do i check whether a particular Email Address is Valid or not,if not valid then catch a exception and report it....
    Also i meant by Valid email address as to be exsisting on that mail server..e.g "[email protected]"...i.e.the user "javamail" should exist on that domain "sun.com"...
    Is there any way which i can do the above thing?
    Also,since i will be sending 1000's of emails every day will it be feasible for me to check each and every email whether it exist or not and then send it.....how much time will it take to do the same...
    Please help me out with this,can anybody give me a Detail desciption and Code of how can i do it...
    Any suggestions are greatly appreciated
    Thanks a million is advance
    Sam

    E-mail generally passes through a whole series of Mail Transfer Agents before arriving on the target machine, and it could be rejected at any stage.
    It may wind up waiting in a queue. It could be days before it reaches a machine that knows whether the user is valid or not.
    And machines aren't as helpful as they used to be about letting out information about available e-mail addresses,
    too many evil spammers about.
    You can test the format, though I've seen a lot of active e-mail addresses with what I believe are invalid characters in them apparently find their way through.
    In theory you could look up the domain part of the address on the DNS. If you don't find either an "A" record or a "MX" record then niether will your mail transfer agent. AFAIK there's no standard java classes for doing that but there may be some out there on the net.
    There's no sure way of validating a user name except sending a mail and see if it bounces.

  • JavaMail API for enabling email notification

    Hi
    I want to use JavaMail API for enabling email notification for an application. I have downloaded the javamail_1.4 zip file, unzipped it and set the CLASSPATH environment variable. JAVA_HOME isalso set. the activation.jar file from JAF is also in place. but, when i try to compile the sample programs (included with javamail) like smtpsend.java,msgsend.java, I get a screenful of errors all referring to "cannot find symbol", the main error being
    "package javax.mail does not exist". I guess, Java is not able to locate the package.
    Please suggest what can be done .Any tips for configuring email notification are more than welcome!
    Thanks!

    Are you compiling using the "javac" command,
    or are you using an IDE like Eclipse or NetBeans?
    In the latter case, you have to tell the IDE to
    add the jar files to your project.

  • I am using iCloud email and my emails are randomly disappearing before I can read them. They are not in any folders on my iPhone and I am having to call apple to have the last 7 days of email sent to me in order to retrieve what is being lost.

    I am using an apple email account and my emails are randomly disappearing before I get a chance to read them. They are not anywhere on my device, not trash, junk etc. The only solution from apple has been to resend me the past 7 days of email in order for me to retrieve the missing emails. This has taken me hours on the phone with apple support with no solution. I just don't know what to do. They have gone over the settings with me and nothing has solved the problem. I don't know where to start since it is happening on all my devices.

    Control-click on the background of the view all pages window and select "Preview Calendar" from the contextual menu.
    You can also save the pdf as a file to compare to the printed calendar.  If the two names are visible in the pdf file then the printed copy should show them.  Contact Apple for a refund.  Apple Print Products - Apple Store (U.S.)

  • Report  showing list of order confirmations and open/close reservations?

    Hi
    Can we have any standard report having list of  order confirmations and open/close reservations in SAP PM ?
    Regards
    Pooja

    Hi Pooja,
    Try IW12, Display Document flow, if you are looking for a combined report of Order confirmations and Material status.There are various other reports related to order confirmations and Material status seperately. For material status you can use IWBK.
    Better place to post PM questions is in Enterprise Asset management Forum.
    Warm regards,
    Srinivas Potluri

  • Sending messages thru email and SMS without using XMS APIs

    Hi,
    I already have some working code that sends messages thru email and SMS. But currently it uses XMS APIs therefore I have a dependency on files like wdk.jar. I want to try and eliminate using the XMS APIs and only use soap to send these messages. I was wondering if there is some documentation available on how I can do this. Also if there a lot of code that needs to be written to do that.
    I primarily want a very simple application that sends only string messages and reduce my dependencies.
    I would really appreciate all the advice.
    Thanks,
    Sonali Nath

    Hi,
    You may refer to the following links to check if they help:
    Sending SCCM Status Messages from MDT Scripts.
    Send SCCM task sequence email report
    Regards,
    Sabrina

  • After getting a new desktop I downloaded iTunes and authorized my new computer and then de-authorized my old one,  When I try to update my 5S it says my phone is not authorized and list my wifes email address as the account holder and not mine.  How

    After getting a new desktop I downloaded iTunes and authorized my new computer and then de-authorized my old one,  When I try to update my 5S it says my phone is not authorized and list my wifes email address as the account holder and not mine.  How do I correct this. I am using Windows 8.1 .  My wife has never had an iTuunes account

    Hello Lakesidetom,
    It sounds as though you are experiencing an issue with an Apple ID and authorizations. Based on your post, it sounds like you are familiar with the authorizing and deauthorizing process. The Apple ID in question (your wife's email) may be originating from the iPhone you are attempting to update. Is it possible that your wife created an Apple ID or iCloud account which is signed in on that iPhone? Below, I have included links to some resources that may help you determine if your wife has created an Apple ID:
    How to find your Apple ID - Apple Support
    Use these steps if you forgot your Apple ID or aren't sure that you have one.
    Apple - My Apple ID
    If you can't remember your Apple ID, just provide us with some information and we'll find it for you. Then we'll help you reset your password.
    Thank you for contributing to Apple Support Communities.
    Cheers,
    Bobby_D

  • How to get the duplicate rows in dynamically generate data table [list items collection] and send emails in sharepoint2010

    Hi,
    i have share point list like  below
    ID   name AdminEmail Useremail   URl   DueDate   UploadSatus
    1    ppp     [email protected]  [email protected]    url  some date    uploaded
    2    yyy       [email protected]   [email protected]   url somedate    empty
    3  xxx         [email protected]   [email protected]    url   somedate   empty
    4  jjj           [email protected]    [email protected]  url     somedate   emp
    AdminEmail and UserEmail  are lookup column
    i using query the list using caml query
    inside of foreach i am checking  two condition like below
    one is upload status in not empty
    i need to send to mail to admin user  this part i have done my adding all list items which have datatable apply group by working fine
    in send condition i am checking difference between DueDate And current date value
    if the value is =1 or -1
    if the value is i
    thank
    i am getting the
    table like below
    ID   name AdminEmail Useremail   URl   DueDate   Upload
    2    yyy       [email protected]   [email protected]   url   somedate    empty
    3  xxx         [email protected]   [email protected]    url   somedate   empty
    4  jjj           [email protected]    [email protected]  url     somedate   empty
    my issue is here  how can i get the dynamic table rows which are same values of AdminEmail and user email  one set and distintict rows are another set
     sets which are same emails are same
    3  xxx         [email protected]   [email protected]    url   somedate   empty
    4  jjj           [email protected]    [email protected]  url     somedate   empty
    set 2
    2    yyy       [email protected]   [email protected]   url   somedate    empty
     how can i get this separate this can any one tell i need to send mail only one time to user [adim and user] .planing to aviod duplicate mail
    Srinivas

    your case better to use the two data tables to store the data
    DataTable dt = list.Items.GetDataTable();
    foreach (DataRow row in dt.Rows)

  • My imac (osx 10.6.8), apple mail(4.5) has begun to act very odd. It quits out and on occasion I open an email to face "plugin is missing" or I have a spinning wheel and the email won't open. New to do list fails to add to the list. Can anyone help?

    Hi all,
    My imac (osx 10.6.8), apple mail(4.5) has begun to act very odd. It quits out and on occasion I open an email to face "plugin is missing" or I have a spinning wheel and the email won't open. New to do list fails to add to the list. Can anyone help?

    Hi all,
    My imac (osx 10.6.8), apple mail(4.5) has begun to act very odd. It quits out and on occasion I open an email to face "plugin is missing" or I have a spinning wheel and the email won't open. New to do list fails to add to the list. Can anyone help?

  • In a hurry, I opened an email that said "order was shipped from "ammazon". I downloaded the order document and it ended up being a zip file. I then realized what it was, and did not actually open the file. This was on my Iphone 5. What should I do now!?

    In a hurry, I opened an email that said "order was shipped from "ammazon". I downloaded the order document and it ended up being a zip file. I then realized what it was, and did not actually open the file. This was on my Iphone 5. What should I do now!?

    Delete the email. The zip file will have no effect on your iPhone.

  • How to get and set the column order in SharePoint list forms

    Hi,
    I want to read the column order of the SharePoint list forms in SharePoint 2003 sites using any of the available web services and need to set the same order
    in the newly created list in SharePoint 2010.
    I am able to read the fields from SharePoint 2003 and creating the list with same fields in SharePoint 2010, but the column order is not maintaining in
    list forms.
    Also, I need to created the views from 2003 site to 2010 site.
    Please help me...
    Thanks in advance...

    Hi,
    Please try to use the following code to programatically change the order.
    SPList list = web.Lists["Example List"];
    if (list.ContentTypes.Count > 0)
    SPContentType ct = list.ContentTypes[0];
    string[] names = {"Example_x0020_One", "Example_x0020_Two", "Example_x0020_Three"};
    ct.FieldLinks.Reorder(names);
    ct.Update();
    Here is a similar thread for your reference:
    https://social.technet.microsoft.com/Forums/en-US/ce66fd65-2882-4bda-8142-89e116d8b90f/how-to-set-the-order-of-the-fields-in-list-forms?forum=sharepointdevelopmentprevious
    Best Regards
    Dennis Guo
    TechNet Community Support

Maybe you are looking for

  • Win 7 Pop up issues

    Hi...Windows 7 just started acting funny after installing a power supply. I know right....I figured maybe one of the daisy linked power cords for HD could be the problem(light on hd was on but diff from before...not as bright sometimes...seen this be

  • Shortcuts for Telephony Toolbar Buttons in IC WebClient release 5.2 (2006s)

    Hi. Has anyone done Assigning hotkeys or shortcuts to Telephony Toolbar Buttons in IC WebClient release 5.2 (2006s)??? This function was possible in the previous release until 5.0 (WinClient) as “Function Key Assignment”. And in CRM 5.2 we have a pos

  • RE: Issues with iPhone 4 sync/charge/restore ERRORS after iOS6 upgrade

    I saw a lot of people through the forum that experienced the exact issue I have and I spent 4 hours trying to resolve it myself with frantic research. What helped me get my iPhone back: This morning I received the message to upgrade my iphone 4 to th

  • How do I upgrade to firefox5

    I have an old version that needs updating but the check for updates is grayed out and I don't know where to login as the admin to change the preferences to allow auto upgrades. If upgrades aren't automated, then how do I upgrade?

  • How to adjust to different screen resolutions in a report

    My question is if we have a report to submit to any officials, we prepare our report by adjusting the line count according to our system screen resoulution,what if the official has other resolution in his system.so please tell me how to solve the pro