Read email Message and process it

Hai friends..
I've just started working with the mail API.. I've gone through the code samples but couldn't get a clear picture on how to extract the body of an email message in some mailbox of mine.. Let me elabourate..
I have an email account say [email protected] which is an smtp based account
smtp address = smtp.mail.xyz.net
pop address = pop.mail.xyz.net
authentication id = abc, password = passwd
I want to extract the contents of an email residing in my INBOX using a java program.. Can somebody send a sample code of how to do this
Warm egards
Dst

Try something like:
Store store = null;
Folder folder = null;
try
// Get a Properties object
Properties props = System.getProperties();
// Get a Session object
Session session = Session.getDefaultInstance(props, null);
// Get a Store object
store = session.getStore("pop3"));
store.connect("mail.hostname.com", -1, "username", "password");
// Open the Folder
Folder root = store.getDefaultFolder();
if (root == null || !root.exists()) {
System.err.println("No default folder");
return;
folder = root.getFolder("INBOX");
if (folder == null || !folder.exists()) {
System.err.println("Unable to located folder INBOX");
return;
folder.open(Folder.READ_WRITE);
int totalMessages = folder.getMessageCount();
if (totalMessages == 0)
return;
// Attributes & Flags for all messages ..
Message[] msgs = folder.getMessages();
// Use a suitable FetchProfile
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.ENVELOPE);
fp.add(FetchProfile.Item.FLAGS);
folder.fetch(msgs, fp);
for (int i = 0; i < msgs.length; i++)
// Do something with msgs;
// Do this to have msg deleted when you close mailbox
msgs[i].setFlag(Flags.Flag.DELETED, true);
catch (NoSuchProviderException e)
System.err.println("Unable to process mail for protocol of '" +
getMailProtocol());
catch (AuthenticationFailedException e)
System.err.println("The username/password was not accepted for the supplied host and port");
catch (MessagingException e)
System.err.println("Unable to process the mail: " + e.getMessage());
finally
if (folder != null)
try
folder.close(true);
catch (Exception e)
if (store != null)
try
store.close();
catch (Exception e)

Similar Messages

  • How do you go back and read email messages stored in untitled 1

    How do you go back and read email messages moved to untitled 1

    Are you using Gmail? There is no "untitled" folder in my 3 mail accounts on the iPad so I am making an assumption here. If you are using Gmail, here is their help site.
    http://support.google.com/mail/bin/answer.py?hl=en&answer=77702

  • When I copy an email message and paste it into a document, the font turns into all symbols.  What's the problem here?

    When I copy an email message and paste it into a document, the font becomes all symbols. What is wrong?

    To use images from the media browser, you must generate previews of the images first. It sounds like the "automatically generate previews for every new project" is turned off under Aperture >Preferences>Previews. To generate a preview for a photo to use in the media browser, right click it and select "update preview". The quality of the preview photo is determined by the settings in the Previews tab found under the Aperture>Preferences menu.

  • Why have I lost read email messages on my iphone?

    I've only had my iphone 4 for a week or so.  All of a sudden today I have lost my read email messages.  I still have them on computer but lost them on the phone.  Also lost my sent messages.  I would like to get them back.  My spouse also has same phone and the same thing happened on his phone as well.

    What is the account type - POP or IMAP?
    Sounds like the account is a POP accout is the sent messages are not available.
    If so, what is the account setting with the email client used on your computer for accessing the account for removing messages from the server after being downloaded by the email client?
    If the email client on your computer is removing messages from the server after being downloaded, the messages will be removed from your iPhone as well since the messages are no longer available on the server.
    Although it is possible to access a POP account with more than one email client, a POP account is designed to be accessed with a single email client only.

  • Inbound email receiving and processing: push and pull

    Hi Experts
    i know there are 2 alternative ways to configure the inbound email receiving and processing: push and pull
    (see also /people/cathy.ma/blog/2009/06/23/introduction-to-the-interaction-center-agent-inbox)
    My question is: what if i configured the email in push and, at the end of day, some emails are not already read by the Contact Center Operator ?
    The day after will the agent see those unread email in the push queue, or in pull in the Agent Inbox (thus transforming them into work item) ?
    Those emails are not lost. True?
    Maybe it is a simplistic question
    thanks for the support
    Angelo T.

    Hello Angelo,
    No, actually. ICI interface "push" emails are handled just like a telephone call. You would never leave a telephone call sitting in the queue at the end of the day, and its the same with ICI emails. The key here is that ICI is real time!  This is quite a different approach than the SAPConnect interface which uses workflow to route the emails to an Inbox (virtual queue). In the Inbox case, of course an agent would see lots of emails sitting in the queue the next day. Hope that helps!
    Regards,
    John

  • Finder share button only has Email, Messages, and AirDrop

    I've successfully added Facebook and Twitter accounts under System Preferences > Internet Accounts yet my Finder share button only has Email, Messages, and AirDrop as options. How can I fix this?

    Thanks for opening the new thread,
    Go to OPTIONS _STATUS and send me the numbers for file free and file total.
    Thanks!
    Click Accept as Solution for posts that have solved your issue(s)!
    Be sure to click Like! for those who have helped you.
    Install BlackBerry Protect it's a free application designed to help find your lost BlackBerry smartphone, and keep the information on it secure.

  • Transaction code to find Process message and Process Instruction

    Hi
    I am new to PP module
    Where do i find (In which Transaction) the list of
    a) Process Message Category
    b) Process message
    c) Process Instruction Category
    in SAP ERP system??
    Regards
    Sweety

    Hi
    Thank u all for responding
    Still I was not able to find certain Process Messages like YQ_AIR, YQ_RPM, YQ_TEMP, YQ_CONS, YQ_PHCO, YQ_PHCO2.
    and Process Instructions like
    YQ_AIR, YQ_ENDPI,YQ_HEAD, YQ_INSTR, YQ_LAY, YQ_MATLI, YQ_PROD, YQ_PTEXT,YQ_RPM, YQ_TEMP, YQ_CON1, YQ_CON2..
    do I need to do some (Basis) configuration to get these?? or the above mentioned Process Messages and Process Instructions are not pre defined??
    Regards
    Sweety

  • How can I attach several images to my Outlook Mac 2011 email message and have all of the images reduced in size while they are being sent out. Thank you

    How can I attach several images to my Outlook Mac 2011 email message and have all of the images reduced in size while they are being sent out. Thank you

    https://discussions.apple.com/message/11994130#11994130

  • Blackberry 8520 keeps repeatedly downloading the same email messages and facebook notifications

    My Blackberry 8520 has all of a sudden started downloading the same email addresses and facebook notifications, that I have already read, I tried deleting them totally and also deleted from my computer inbox, but it just downloaded the next lot in my inbox repeatedly instead.  Sometimes it says I have 50 unread messages, which is the same 7 or 8 messages over and over again, showing as unread. 
    I have rebooted device several times and don't know what else to do now, can anyone help please?
    Thanks very much

    Hi and welcome to the forums!
    Have you changed the settings for messages on your account on the providers website?
    (Gmail, Yahoo, etc.)
    If that's not it try the following:
    Go to options advanced options, Host Routing Tables, click to enter. DO NOT click on any listing.
    Press menu key, and select register now.
    You will get a verification message. Then go to email settings and send service books.
    I would suggest  logging into the carriers BIS site via PC if you can.
    You will get an email per account. Repeat the battery pull and see if the problem is
    resolved.
    Let us know how it goes!
    Thanks,
    Bifocals
    Click Accept as Solution for posts that have solved your issue(s)!
    Be sure to click Like! for those who have helped you.
    Install BlackBerry Protect it's a free application designed to help find your lost BlackBerry smartphone, and keep the information on it secure.

  • I opened a PDFs file that was attached to an email message and now it will not close when I press "Done" as it usually does. Does anyone have a solution to suggest? Thanks.

    I opened a pdf file that was attached to an email message I received and now it will not close when I press "Done" as files usually do. Does anyone have a solution to suggest please? Thanks.

    Try double clicking your home button then force close the stuck PDF by swiping upward. Once you've done that just click the home button again to exit.

  • Read email message with AppleScript

    Hi!
    I just used this tip to remotely sleep my MacBook Pro:
    http://www.tuaw.com/2008/04/07/applescript-control-your-mac-with-an-e-mail/
    Now I would like that when the message comes with the subject as System and the text as Read an applescript would read what I wrote after that.
    Example:
    From: Me
    Subject: System
    Text: Sleep
    -> The computer runs applescript sleep and sleeps (so far it's working)
    From: Me
    Subject: System
    Text: Read
    -> The computer runs applescript read (that's the problem)
    How do I point the AppleScript to the received message and make it start reading?
    Is there a way to also unlock the screen (screensaver uses password)?
    Tank-you in advance for any help!

    The trick here (and the part that TUAW doesn't cover in that article) is that when a Mail rule triggers an AppleScript it passes a list of relevant messages to the script.
    Once you have that it's easy to act upon the message content.
    So instead of the simple shutdown script you write something more like:
    using terms from application "Mail"
     on perform mail action with messages theSelectedMessages for rule theRule
      repeat with eachMessage in theSelectedMessages
       -- Process the current message
       -- YOUR CODE HERE
      end repeat
     end perform mail action with messages
    end using terms from

  • Scenario to recevie a message and process the fields

    Hi,
    I am new to JMS and I have a scenario :
    I will be getting a message from MQ queue and I have to read that message object and parse using a delimiter | and process the fields to a POJO class to pass to another program X.java.
    Now X.java will pass the parameters to a web service and print a document.
    So It would be great if you can help me out on steps to acheive this task. I am reading about JMS and understood that i have to code a MDB class which reads the message object in onMessage method ?
    Thanks
    Mohit

    Hi,
    I am new to JMS and I have a scenario :
    I will be getting a message from MQ queue and I have to read that message object and parse using a delimiter | and process the fields to a POJO class to pass to another program X.java.
    Now X.java will pass the parameters to a web service and print a document.
    So It would be great if you can help me out on steps to acheive this task. I am reading about JMS and understood that i have to code a MDB class which reads the message object in onMessage method ?
    Thanks
    Mohit

  • I swipe an email message and sometimes get "delete" and sometimes "archive"

    Recently, I have been swiping emails to delete them and instead of delete, the red message on the right side of the email message says "archive". There have been a few, however, which still say "delete". Could you help me get rid of the archive or tell me what it is there for? It seems, perhaps that the deletes are for my .me account and the archives for my gmail account. Any way to change that? Thanks

    is there a way to disable archiving when gmail is set up through exchange? -- or a way to push email on gmail rather than fetch?

  • Mailto: hyperlink opens both a new email message and a new browser window/tab

    Hi,
    The subject line sums it up.  I have  form with email hyperlinks, which work fine except that when you click on them they seem to open both a new message in the registered email client, AND a new window/tab in the default web browser.
    I prefer using mailto: hyperlinks instead of some other hack to open a new email message.
    Does anyone know of a way to get these to work without a new browser tab/window being opened?
    Thanks,
    Eric

    The SMTP settings are separate from the POP or IMAP settings within Mail.app (which can be a little confusing), and the SMTP settings are incorrect.  That could be some combination of the username or password, the SMTP server name, the TCP port, whether or not SSL is in use or not.  It's more common to have SSL enabled.  All have to be correct.  The required SMTP server settings do vary by mail provider, unfortunately.  You can use Connection Doctor to get more details on the particular error; Window > Connection Doctor, then open the drawer for a look at additional details.  If you're not able to resolve the error from that output and from the mail provider's available documentation, and establish the connection, please scrub any personal details from the detailed diagnostics, and post that output here.

  • Can't get sound on emails, messages and alerts on iPad 1

    My iPad doesn't have sound onr emails, messages or alerts

    If you lose sounds for keyboard clicks, games or other apps, email notifications and other notifications, system sounds have been muted.
    System sounds can be muted and controlled two different ways. The screen lock rotation can be controlled in the same manner as well.
    Settings>General>Use Side Switch to: Mute System sounds. If this option is selected, the switch on the side of the iPad above the volume rocker will mute system sounds.
    If you choose Lock Screen Rotation, then the switch locks the screen. If the screen is locked, you will see a lock icon in the upper right corner next to the battery indicator gauge.
    If you have the side switch set to lock screen rotation then the system sound control is in the task bar. Double tap the home button and in the task bar at the bottom, swipe all the way to the right. The speaker icon is all the way to the left. Tap on it and system sounds will return.
    If you have the side switch set to mute system sounds, then the screen lock rotation can be accessed via the task bar in the same manner as described above.
    This support article from Apple explains how the side switch works.
    http://support.apple.com/kb/HT4085

Maybe you are looking for