How to get unread messages

Hi,
I have the following code
Folder folder=store.getFolder("INBOX");
Message[] message=folder.getMessages();
The getMessages method is supposed to return all the messages from inbox,but I only get new messages.I can read the new message but,how can I mark the message that I already read.When I run my program,it always reads all the new messages.What I mean is,in outlook,all the new messages are highlighted,my program can always read those.How can I make the message without highlight.I am using POP3 for incoming mail.
Thanks
Ravi.

hello friends if you are reading mail from gmail use following properties
props=System.getProperties();
             props.setProperty( "mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
            props.setProperty( "mail.imap.socketFactory.fallback", "false");
            props.setProperty("mail.imap.port", "993");
            props.setProperty("mail.imap.socketFactory.port", "993");// for gmail
               props.put("mail.imap.host", "imap.gmail.com");
auth=new SMTPAuthenticator("[email protected]","password");
                  session=Session.getDefaultInstance(props,auth);
          store=session.getStore("imap");
by checking flag values you can differentiate mail is read or unread
     Flags flags=msg[k].getFlags();
                        Flags.Flag[] sf=flags.getSystemFlags();
               for (int i = 0; i < sf.length; i++) {
                  if (sf[i] == Flags.Flag.DELETED)
                      System.out.println("DELETED message");
                       else if (sf[i] == Flags.Flag.SEEN)
                      System.out.println("SEEN message");
                      else if (sf[i] == Flags.Flag.ANSWERED )
                      System.out.println("ANSWERED  message");
                      else if (sf[i] == Flags.Flag.DRAFT )
                      System.out.println("DRAFT  message");
                      else if (sf[i] == Flags.Flag.FLAGGED)
                      System.out.println("FLAGGED message");
                      else if (sf[i] == Flags.Flag.RECENT)
                      System.out.println("RECENT message");
                      else if (sf[i] == Flags.Flag.USER)
                      System.out.println("USER message");
or check
msg[k].isSet(Flags.Flag.SEEN)
is true or false

Similar Messages

  • How to get unread message count

    I m working in mail application where i need to get the unread message count.Can anyone help me out in solving this issue ,is there any specific method available in javamail to get this count.
    Thanx in Advance

    Is there some reason you're unable to read the
    javadocs? Did you find them too confusing?
    What's wrong with the method Folder.getUnreadMessageCount?
    Oh, and if you're using POP3 instead of IMAP,
    read the FAQ and the com.sun.mail.pop3 package
    javadocs.

  • To get unread messages in any folder "exactly once"

    What am trying to do?
    a. Poll the mail server(might be MS or gmail or yahoo..) (say now).
    b. Get unread messages from a mailbox folder via IMAP. (via +'SEEN'+ flag)
    c. Process the unread messages i.e. in my case i will send SMS to users according to filters specified.
    d. Sleep and Poll the mail server after 10 min(say)
    e. Now the question is how to do i get the next set of unread messages i.e. the unread messages other than those that i got in step (b)
    Rules-
    a. Note that i can't set the message as '+READ+' or '+SEEN+' as mine is not the standard client.
    b. I think i can get hold of the largest message UID in the first poll and save it and in the next poll try to retrieve only the unread
    messages with UID greater than that i saved. +But is there any good and easy approach to do the above+?
    c. Also to be clear, in the interim period between two polls, if the user really reads a mail via his/her client, then in the next poll i am not interested in those read mails. So the question arises only if the user doesn't check any mail where my application really comes into picture
    Please assist. Ping me if am unclear.

    Thanks. It's working for 'IMAP'. I need it for IMAP only.

  • How to get automatic message output

    Hi,
    How to get automatic message output while creating po cause i have done all setting in the config but still it does not work what else i have to do.
    And 1 more thing how we can maintain condition record for Printoutput & External send for one output type.
    Regards,
    Anant

    Hi,
    Please follow the below steops for the Output of Purchase Order
    1. Condition Table
    SPRO > Material Management> Purchasing -> Message -> Output Control->Condition Tables->Define Condition Table for Purchase Order
    Select:
    Purchasing Doc. Type, Purch. Organization, Vendor
    2. Access Sequences
    SPRO ->     -> Purchasing -> Message -> Output Control->Access Sequences->Define Condition Table for Purchase Order
    3. Message Type
    SPRO -> Material Management-> Purchasing -> Message -> Output Control->Message Types->Define Message Type for Purchase Order
    *4. Message Determination Schemas*
    4.1. Message Determination Schemas
    SPRO -> Material Management-> Purchasing -> Message -> Output Control->Message Schema->Define Message Schema for Purchase Order-> Maintain Message Determination Schema
    4.2. Assign Schema to Purchase Order
    SPRO -> Material Management-> Purchasing -> Message -> Output Control->Message Schema->Define Message Schema for Purchase Order-> Assign Schema to Purchase Order
    5. Partner Roles per Message Type
    SPRO -> Material Management-> Purchasing -> Message -> Output Control-> Partner Roles per Message Type ->Define Partner Role for Purchase Order
    6. Condition Record
    Navigation Path: SAP Menu-> Logistics -> Material Management -> Purchasing-> Master data-Messages- MN04
    Here you can maintain the condition record.
    All above steps u can do from transacton NACE also
    now when u create po in the messages u will get the out put method as u have maintained in the above steps.
    Regards,
    Manish

  • Before page refresh how to get alert message

    Hello ..
    If user refreshes webpage then from flex side how to get alert message.
    Thanks in advance.

    If you don't want it to say "Microsoft Internet Explorer," you can use a different browser. :-)
    But, seriously...
    If you really want to customize the appearance of a dialog, you can make one with DHTML that looks like anything you want. You can make it look like a system dialog if you want, but you don't have to. (In fact, if you make it look like a Windows dialog, it will stick out like a sore thumb if someone is using another OS.)
    I had to create some of these for an online testing application I wrote, because they wanted the tests to be timed, and I discovered that, in Internet Explorer, you could stop the clock just by opening certain dialogs, so I had to suppress "right-clicking," remove the menu bars, and use custom dialogs to communicate with the user. Since then I've re-used these dialogs in a number of other projects. They're pretty handy.

  • How to get Mac Messages to NOT save chats?

    How to get Mac Messages to NOT save chats?
    I went through the Preferences but I do not see where I can check/uncheck save chats.  Will someone help direct me?

    Hello mayonnaise18,
    Thank you for the question.  You can disable the option to save chats in the Messages tab in Messages>Preferences:
    Automatically save conversations when you close them
    Choose Messages > Preferences, and then click Messages.
    Select “Save history when conversations are closed.”
    These steps are to enable the option to save messages, but you would want to uncheck the option to "Save history when conversations are closed."  You can find the full article here:
    Messages (Mountain Lion): Save conversations
    http://support.apple.com/kb/PH12012
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • How to get flagged messages in to tasks or alternatively view another users to do list.

    If someone could just help me out I would be extremely appreciative.
    2 of us work in one mail box together called admin. when one of us is away we like to use the flags to create follow ups for each other on certain email items.
    Firstly, I can only see my main accounts to do list
    Secondly, when I flag a contact / message / anything in fact, in any mailbox it only appears in their respective to do lists and not in their tasks. Thus I cannot see what I have flagged for them at a glance as I can not find a way to view other peoples
    to do list. i.e. neither of us can see any of the flags in the shared mailbox we use (admin) unless we log in under a different profile, which is troublesome as it takes way to long to switch back and forth.
    I presently use colour categories to delegate who is currently in charge of answering certain emails and use custom flags to note what we are waiting for in particular to a certain email and then mark a tick when it has been dealt with. Simple system but
    not currently working in full due to the follow up flags not appearing in tasks.
    This also affects my task synching on my mobile where once again it only shows what is in tasks... i.e stuff I have physically typed in outlook rather than flagged content; mails, contacts etc.
    Any ideas how to get the follow up flags appearing in tasks or an ability to see other peoples to do lists... the first is more preferable but I will take what I can.
    Kindest Regards
    Woody

    Just add the 'admin' mailbox as additional account in Outlook, as opposed to additional mailbox (i.e. don't add it from Accounts Settings -> More settings -> Advanced, but from File -> Add account instead).
    It will then show flagged items and tasks from all accounts in the 'To-do' list.

  • How to get a message in a view which was raised in another view?

    Hi All,
    I have used the view manager message serviice to add my custom error message in BT126H/Apptdetails view. So if the validation fails then the message is displayed on the screen . But when I am saving the transaction the error message is getting disappeared and I am able to save the transaction. So just before saving ie in the method EH_ONSAVE in overviewset view I will query that message but as it was added in the appt details view I am not getting that message in overview set .
    Can anyone tell me how can I get that particular message in overview set?
    Thanks and Regards
    Sweta

    hi,
    In your Subinventory LOV add Bin variable using it Query tab. which has Bind VAriable And View Criteria section.use Bind Variable section. those are in the view object level.
    then your all lov include view object select and choose it View Accessors section. it has your lov and Edit your Subinventory LOV and then popup dialog box. Inside it you can make Inside Parametor section select relevant bind variable name and it need value.
    thaks.

  • How to get the message from a Runnable class

    The Schedule class is actually a JFrame, what I want to do is to "get" the message from Scheduler Class and display it in a JTextField, to let user know what is doing.
    How can I approach this?
    public class Schedule {
        @SuppressWarnings("static-access")
        public static void main(String args[]) throws InterruptedException {
            final Scheduler s = new Scheduler();
            Thread t = new Thread(s);
            t.start();
    public class Scheduler implements Runnable{
    private static int actionType;
    private static String msg;
        public static void setMsg(String msg) {
            Scheduler.msg = msg;
        public static String getMsg() {
            return msg;
        public void run() {
            //System.out.println((int)(Math.random() * 1000));
            actionType = 1;
            while(true){
                try {
                    switch(actionType){
                        case 1:
                            setMsg("Process actionType: "+actionType);
                            break;
                            case 2:
                            Thread.sleep(2000L);
                            setMsg("Process actionType: "+actionType);
                            break;
                            case 3:
                            Thread.sleep(2000L);
                            setMsg("Process actionType: "+actionType);
                            break;
                            case 4:
                            Thread.sleep(2000L);
                            setMsg("Process actionType: "+actionType);
                            break;
                    actionType++;
                    if(actionType>4){
                        actionType = 1;
                } catch (InterruptedException ex) {
                    System.out.println("Scheduler.run:"+ex.toString());
    }

    Or with only one loop:
            int actionType = 0;
            while (true)
                actionType = (actionType % 4) + 1;
                msg = "Process actionType: " + actionType;
                try
                    Thread.sleep(2000L);
                catch (InterruptedException ex)
                    System.out.println("Scheduler.run:" + ex.toString());
            }

  • How to get the message Sender's information in MSMQ?

    Hi, everyone
    I am going to develop a Windows server to monitor the messages in MSMQ. Now I wanna get the message sender's name(that is the API of this message, like class name or function name of who send the message.) I make a simple demo and it can easy to get
    the message body. But is it possible to get the sender's info by using any MSMQ method ? Looking forward any answers. Thanks so much.
    Shuo Lei

    Hi,
    Sender object is type of object any time if you want to use any property/attribute of sender object first you need to type cast it with your desire object.
    For more information, you could refer to:
    http://blog.jsinh.in/managing-msmq/#.VPe5mnkfqM8
    http://forums.asp.net/t/343932.aspx?How+can+I+get+values+of+sender+object+in+C+
    Regards

  • So I have an Apple iPod the 5th gen and idk how to get my messaging to work

    Hello?
    My name is Hailey and I have the 5th gen of an iPod touch and my friend has the same one we'll she got her messaging texting thing working I was wondering how to get mine to work? Because it's not working and I've followed the instructions. Please help me

    See:
    iOS: Troubleshooting applications purchased from the App Store
    Contact the developer/go to their support site if only one app.
    Restore from backup. See:
    iOS: How to back up              
    Restore to factory settings/new iPod

  • HELP. How to read unread message from Gmail?

    Folder inbox = store.getFolder("INBOX");
              inbox.open(Folder.READ_ONLY);
              FetchProfile profile = new FetchProfile();
         profile.add(FetchProfile.Item.ENVELOPE);
    System.out.println(inbox.getUnreadMessageCount());
    It print out the number of all messages. I just want to get it number of unread message.
    I have bean searching for a long time. Is there any one can help me. I just want to make a Gmail notifier. Ring me when I get unread email.

    Are you using IMAP or POP?
    Did you read the JavaMail FAQ entries about Gmail?

  • How to get bundled message resource in validation.xml?

    Hi,
    Is it possible to get a bundled message resource in the validation.xml? Basically i want to do the following validation:
    <form name="testForm">
             <field property="name" depends="required">
                  <arg0 key="form.testForm.name" />
             </field>
    </form>But the message "fom.testForm.name" is stored in a resource file stated as below in struts-config.xml:
    <message-resources parameter="com.test.TestResources" key="test"/>Means if u want to use this message in jsp, u need to add bundle="test". In this case, how to write the validation? Possible to get this message?

    u can give your message key value pair the default
    application resource bundle..Do u mean that here i could only use default application resource messages? Other resource messages could not be used for validation?

  • I began to purchase songs off iTunes, a prompt message appears whether you want to buy the song after the first click... I ticked the box to say I didn't want this warning again... But now I wish I had that - Anybody know how to get that message back???

    I began to purchase songs off iTunes, a prompt message appears whether you want to buy the song after the first click... I ticked the box to say I didn't want this warning again... But now I wish I had that - Anybody know how to get that warning/prompt message back???

    Sign-in to your iTunes Store account (Store menu > View my account).
    At the bottom of the Account Information page is a Reset box to click to reset all warnings for buying and downloading.  Click the "Done" button when you're finished.

  • To get unread messages Pop3 vs IMAP

    Hi all.
    I read all API's documentation and I have this common trouble; I understood that with pop3 it's not possible to read flags and get unread mails.So, can I have some links with the official documentation about imap protocols to get unread mails?

    I tried with the HashMap and I wrote this code:
                          ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("uid.txt"));
                                   HashMap2<String, String> hash  = new HashMap2<String, String>();
                        POP3Folder folderPOP = (POP3Folder) folder;
                        Message[] messages = folderPOP.getMessages();
                        for(int i = 0; i<messages.length; i++){
                             String uid = folderPOP.getUID(messages);
                             hash.put(uid, uid);
                        out.writeObject(hash);
    out.close();
    folder.close(false);
                   store.close();
                        This one save all UIDs in a file named 'uid.txt'.
    Then, with a new session, store and folder, I query inbox to get unread mails:POP3Folder folderPOP = (POP3Folder) folder;
                        Message[] messages = folderPOP.getMessages();
                        ObjectInputStream in = new ObjectInputStream(new FileInputStream("uid.txt"));
                        HashMap2<String, String> hash = (HashMap2<String, String>) in.readObject();
                        for(int i =0; i<messages.length; i++){
                             String uid = folderPOP.getUID(messages[i]);
                             if(!hash.containsKey(uid)){
                                  System.out.println("New message from: " +messages[i].getFrom()+ " subject: " +messages[i].getSubject());
                        in.close();
    folder.close(false);
                   store.close();HashMap2 is a Class which extends HashMap and implements Serializable interface.
    This code doesn't work. It says that there aren't new mails!
    Where am I wrong?
    Edited by: Kondarondus on Feb 23, 2009 4:51 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Maybe you are looking for