POP3 problems

Hi guys!
I have a problem using JavaMail implementing a simple Mail download system:
My code is the following:
Session session = null;
Store store = null;
Folder folder = null;
try {
session = Session.getDefaultInstance(System.getProperties(),null);
store = session.getStore("pop3");
store.connect(<POP3SERVER>,<USERNAME>,<PASSWORD>);
if (store.isConnected()) System.out.println("connected");
folder = store.getDefaultFolder();
folder.open(folder.READ_ONLY);
Folder list[] = new Folder[10];
list = folder.list();
System.out.println(list[0].getName());
Message[] msg = folder.getMessages();
     for (int i = 0; i < folder.getMessageCount(); i++)
     System.out.println(msg.getFrom());
     System.out.println(msg[i].getSubject());
folder.close(true);
} catch(Exception ex){
System.out.println(ex.getMessage());
The output in the console is:
connected
open
Press any key to continue.... :-)
Why I can't get the message content?
Could someone tell me?
Thank you very much.
Giuseppe

- See if there are any messages in your default folder. Also, verify whats your default folder. If you think there are messages, just print a log for getMessgaeCount()
- Or open a specific folder such as "INBOX".
Check out this article, this has some sample code.
http://www.javaworld.com/javaworld/jw-10-2001/jw-1026-javamail-p2.html
HTH.

Similar Messages

  • Hi javamail pop3 problem

    hello...
    i have a written code for retrieving mail from pop3 server...and its working fine except one problem....(if it is a problem)....
    when i retrieve mails i open outlook express and it again retrieves the same mails i have retirieved from my code....is this a normal behaviour as pop3 deletes all the retrieved messages....and when i first receive message using outlook my code is unable to find those messages .....so why this difference....should my code deliberately and explicitly delete messages after retrieving them or pop3 does it as its default behaviour....

    The emails on the POP3 server are not deleted from the server as they retrieved.
    In Outlook Express as well as in Outlook you can set the properties for your email account to leave a copy of the message on the server. The initial setting is to delete the message from the server as you retrieve it.
    In JavaMail in order to delete the email from the server you need to open the folder object for Read/Write, then to set the DELETED flag on the message to �true�;
    When you close the folder, deleted messages will be removed if you set the expunge parameter to �true�.
    As in the following code:
    Folder folder = store.getFolder("INBOX");
    folder.open(Folder.READ_WRITE);
    Message message = folder.getMessage(1);
    message.setFlag(Flags.Flag.DELETED, true);
    folder.close(true);

  • JavaMail Pop3 problems

    I am trying to read emails from a pop3 account. Even using the code provided by sun in the JavaMail examples directory, I can't seem to connect. I am getting this error:
    java.net.ConnectException: Connection refused: no further information
    at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:63)
    at javax.mail.Service.connect(Service.java:227)
    at msgshow.main(msgshow.java , Compiled Code)
    Can someone explain to me how to remedy this problem? Thank you in advance.
    Jimmy

    I have a similar problem . I want to extract the contents of the mail which is nothing but FORM ,with a set of KEY_VALUE pair to ACCESS.Can anybody help me with this issue?It is urgent!!!

  • Nokia 6233 pop3 problems !!!

    i have a problem trying to connect to my companies pop3 server on which i'm using ssl - port 995..
    so i'm always getting message "check failed" - and in details it says "certificate not present"..it doesn't ask me anything to accept..just this error..does anyone have a clue or solution..
    regards..

    11-Feb-2008 09:09 AM
    amircygmira wrote:
    If I update my phone software will this problem go away?
    It should fix it.
    www.nokia.com/softwareupdate
    If it doesn't fix it visit a nokia care point/service centre.
    Care points:
    UK
    http://www.nokia.co.uk/A4228006
    Europe:
    http://europe.nokia.com/A4388379
    Elsewhere:
    http://www.nokia.com and select your country.

  • POP3 problems Peterchurch area (01981) ??

    Hello,
    My first post on the forum so please excuse any errors.
    I look after the computer and internet equipment belonging to two elderly ladies. Both are in the (01981) exchange and both have BT Broadband Option 1. For the last two days they have both had intermittent problems collecting their email by POP3. I have been monitoring this from my computer by setting up POP3 connections on my own computer using their details. (I an 400 miles away). There is no problem with webmail, so I know their email addresses and passwords are OK. However, when I look at the diagnostics at my end it is the POP3 password that is intermittently failing for both accounts. It seems a coincidence that they are both on the same exchange and both suffering intermittent problems.
    Can anybody help? The ladies are not able to handle a technical phone call, and I am not due to visit them for some months. If there is a known problem in the Peterchurch area which will be fixed soon that would be great to know and I could put their minds at rest.
    Thanks
    Solved!
    Go to Solution.

    gterry wrote:
    Hello,
    My first post on the forum so please excuse any errors.
    I look after the computer and internet equipment belonging to two elderly ladies. Both are in the (01981) exchange and both have BT Broadband Option 1. For the last two days they have both had intermittent problems collecting their email by POP3. I have been monitoring this from my computer by setting up POP3 connections on my own computer using their details. (I an 400 miles away). There is no problem with webmail, so I know their email addresses and passwords are OK. However, when I look at the diagnostics at my end it is the POP3 password that is intermittently failing for both accounts. It seems a coincidence that they are both on the same exchange and both suffering intermittent problems.
    Can anybody help? The ladies are not able to handle a technical phone call, and I am not due to visit them for some months. If there is a known problem in the Peterchurch area which will be fixed soon that would be great to know and I could put their minds at rest.
    Thanks
    Hi gterry.
    There is currently a problem with email access at present, but showing against varous email accounts, and seemingly random in nature.
    I believe that one or more of the backend load balancing servers is sick, faulty or under severe overload - hence causing the email problems many people are seeing (reports in forums and newsgroups confirms this).
    http://www.andyweb.co.uk/shortcuts
    http://www.andyweb.co.uk/pictures

  • GMail POP3 problem: Not getting messages with sender "me"

    HI guys,
    I have an account called [email protected] , I successfully sent mails to the same using javamail.In this messages,sender is marked as "me".
    Now I want to read all the messages in inbox,including the messages sent by same account itself.(messages with "me" sender).
    But I notices that javamail doesnt read any messages which the sender is "me".
    Is there a solution for this?
    thanks in advance,
    umanga
    Edited by: virtualumanga on Jun 6, 2008 7:09 PM
    Edited by: virtualumanga on Jun 6, 2008 7:10 PM

    Ok.Heres what happens.
    When I send emails to the same account using gmail webbase application , those mails (which the sender is "me") are read from my Java-POP3 code.
    But when I send mail using my Java-SMTP code , and try to retrieve them using same Java-POP3 program,those mails are not read.
    Here is my temp account that I am using
    user : [email protected]
    password: umanga123
    You can see there are 3 mails (please dont delete them) , which were sent using my Java-SMTP code.And one mail which is,sent from my yahoo account.
    Below Is the java-POP3 code that I am reading my messages.You can run them your self and see that the messages with "me" and not reading,only the message from yahoo is reading.
    You can test following code without any modifications..
    Please help,
    thanks in advance.
    public class MailGet {
         public static void main(String args[]) throws Exception
              String host="pop.gmail.com";
              String user="fhb.test";
              String pwd="umanga123";
              //String from="[email protected]";
              //String to="umanga@quicksilver";
              Properties props=new Properties();
              props.put("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
              props.put("mail.pop3.socketFactory.fallback", "false");
              props.put("mail.pop3.port", "995");
              props.put("mail.pop3.socketFactory.port", "995");
              //FileInputStream fis=new FileInputStream("/home/umanga/pop.prop");
              //props.load(fis);
              Session session=Session.getDefaultInstance(props,
                        null);
         try {     
              Store store=session.getStore("pop3s");
              store.connect(host,user,pwd);
              Folder folder=store.getDefaultFolder().getFolder("Inbox");
              folder.open(Folder.READ_WRITE);
             System.out.println("Getting messages");
              Message msg[]=folder.getMessages();
             System.out.println(folder.getMessageCount()+" "+folder.getUnreadMessageCount());
             for(int i=0;i<msg.length;i++)
                  System.out.println("Subject: "+msg.getSubject() );          
         folder.close(true);
         } catch (Exception e) {e.printStackTrace(); }     
    Edited by: virtualumanga on Jun 7, 2008 4:45 AM
    Edited by: virtualumanga on Jun 7, 2008 4:46 AM
    Edited by: virtualumanga on Jun 7, 2008 5:21 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Nokia messaging - Telia Pop3 problem

    I have created  a Nokia messaging account with two mail account with success.
    But adding my Telia pop2 account fails. It seems that the Telia pop3 server "mailin.telia.com" cannot be accepted.
    Any hints would be appreciated.
    Best regards,
    Tobbe

    Filed a bug report for this. Thanks,
    -Davis 

  • POP3 problems after adding a Yahoo account to Outl...

    I have just created a new Yahoo account and want to send and receive e-mails with it through Outlook 2003; however every time it tries to send and receive, I get a message saying the POP3 server needs my password (which is already saved).  When I enter it, the message disappears and comes straight back up again.  I'm able to send but not receive mail through the Yahoo account.
    I also have an AOL account that I have been accessing via Outlook for several years, and this works fine.
    Any suggestions would be gratefully received, as I have spent hours trying different settings with no luck - thanks!
    Solved!
    Go to Solution.

    lesleyelias wrote:
    I have just created a new Yahoo account and want to send and receive e-mails with it through Outlook 2003; however every time it tries to send and receive, I get a message saying the POP3 server needs my password (which is already saved).  When I enter it, the message disappears and comes straight back up again.  I'm able to send but not receive mail through the Yahoo account.
    I also have an AOL account that I have been accessing via Outlook for several years, and this works fine.
    Any suggestions would be gratefully received, as I have spent hours trying different settings with no luck - thanks!
    Hi.
    Is this an actual Yahoo.co.uk email address ?
    Have a look at the following :-
    http://www.ehow.co.uk/how_6518718_set-up-pop3-yahoo-mail.html
    in c ase you need to allow the account to be "popped"
    (you might need to replace the ".com" with ".co.uk" for the pop/smtp server settings.)
    http://www.andyweb.co.uk/shortcuts
    http://www.andyweb.co.uk/pictures

  • POP3 Issues Still - Help!

    I am continuing to have POP3 problems and have had NO luck with Apple's tech support (over the phone or at the Apple store) with this. Here's what happens: The iPhone is set to never remove from the server. I'll receive several emails, and everything looks fine. At a later point, I'll receive another email, and suddently the previous emails give me the "This message has not been downloaded from the server." message. Although they were there before. And I can see the "preview" of them in my inbox. I even changed the preview to 5 lines (after the problem) and can see the first 5 lines of the email, so I know it's on the phone.
    Now the problem gets even worse: When I open Outlook on my computer, the emails that were still working on the phone download just fine. The ones that were giving me the error message are GONE. So now I've completely lost those emails and can't recover them!!!
    Has anyone else seen this happen? Is there a workaround? The guy at the Apple store actually told me "that's the nature of POP3 email"!!! He also suggested I get a .Mac account. I really don't want to spend my $100 rebate just to get a feature on the phone to work like it should.
    I may see about getting my email server setup for IMAP, but in the meantime I really need the POP3 to work correctly.
    Help?

    Based on a number of reports here, this seems to be some sort of bug. I access a business POP account with my iPhone (with the same setting - not removing messages from the server when downloaded) and I access the same account with the Mail.app on my Mac and with Outlook on a PC running Windows XP. I don't have the Mail.app or Outlook actively/automatically checking for new messages along with the iPhone and I haven't experienced the same yet.
    My .Mac account is checked for new messages automatically with the Mail.app on my Mac (24/7) along with my iPhone and I've experienced zero problems with this account which is accessed as an IMAP account.
    Do you have Outlook set to automatically check this account for new messages which is active and running most of the time?

  • Cannot get email

    getting error message...cannot get mail, connection to server failed.
    actually mail is being sent ok (as received by addressee) but emails not being received.
    feels like a pop3 problem on my iPhone 4s, since emails both sent and received on laptop ok.
    i Can't find how to examine pop3 settings of my established email acct.
    thoughts?

    when you don't provide us with the info of your email providers we can't really google their pop3 settings in terms and server to advice you to double check if your settings are correct and if your carrier allow the required ports to be used

  • Problem with configuration Internet SMTP/POP3 Server profile in Siebel

    I cannot recieve in siebel mail from mail server.
    First problem is my mail server using IMAP protocol instead POP3
    Is the config in profile the same as POP3 but using another port (143 for IMAP)?
    Second security of mail server wants to Check authenticity of the user - how it configure in profile in siebel?

    The information is found in "Siebel Maintenance Release Guide Version 8.0.0.x". You need access to My Oracle Support (Metalink 3)
    to get to that information.
    Search for "ACR 374"
    Axel

  • I have an Ipad 2 and are having problems sending out emails in one of my email address. I always get a message reading the email was not sent because the server does not allow relaying. This is an email account POP3. I have no such problem with gmail.

    I have an Ipad 2 and are having problems sending out emails in one of my email address. This is a POP3 email Account? I always get a message reading that the email was not sent because the server does not allow relaying. I have no such problem with gmail. What could be the problem and how do I resolve this. Is it about settings?
    Richard.

    Welcome to the Apple community.
    If you are unable to remember your password, security questions, don’t have access to your rescue address or are unable to reset your password for whatever reason, your only option is to contact Apple ID Support, upon speaking to an operator you should explain that your problem is related to your Apple ID, this way you will not be charged for assistance, even if you don’t have an AppleCare plan.
    The operator will take you through some steps you may have already tried, however they need to be sure they have exhausted all usual approaches before trying to reset your account, so you should try to be helpful and show patience with the procedure.
    The operator will need to verify they are speaking to the account holder and may ask you some questions that only the account holder could know, and you will need to answer them if the process is to proceed.
    Once the operator has verified your identity they will send a message through to your device which contains an alpha numeric code, which you will need to read back to them.
    Once this has been completed they will send an email to your iCloud email address after a period of 24 hours, so you should check that mail is enabled in your devices iCloud settings.
    Upon receipt of the email, use the reset link provided to reset your password, after which you should be able to make the adjustments to iCloud that you wish to do.

  • Problem in sending mail for a pop3 account using transport.send(msg)

    hi,
    i am having problem in not able to send mail for a pop3 account ...
    I have written an email gateway which listens to my pop3 account...on email arrival it listens nd extract the contents and send it as an sms msg...upon failure it needs to deliver the mail to sender id.I am using quartz to listen.
    i am using jboss for server and java mail api.
    here is my code
    MimeMessage mimemsg = new MimeMessage(session);
                                                           mimemsg.setFrom();
                                                           mimemsg.setRecipients(Message.RecipientType.TO, to);
                                                           mimemsg.setSubject(subject);
                                                           mimemsg.setText(parsedText);
                                                           mimemsg.setSentDate(new Date());
                                                           mimemsg.setContent(strBuff.toString(), "text/html");
                                                           System.out
                                                                                    .println("Before sending mail");
                                                           Transport.send(m);
                                                                System.out.println("message sent successfully");
    excepition i am getting is :
    2008-09-12 11:45:11,140 INFO [STDOUT] Before sending mail
    2008-09-12 11:45:11,140 ERROR [STDERR] javax.mail.IllegalWriteException: POP3 messages are read-only
    2008-09-12 11:45:11,140 ERROR [STDERR]      at com.sun.mail.pop3.POP3Message.saveChanges(POP3Message.java:438)
    2008-09-12 11:45:11,140 ERROR [STDERR]      at javax.mail.Transport.send(Transport.java:97)
    2008-09-12 11:45:11,140 ERROR [STDERR]      at com.openstream.emailgateway.sources.ListenEmailGateway.execute(ListenEmailGateway.java:422)
    2008-09-12 11:45:11,140 ERROR [STDERR]      at sun.reflect.GeneratedMethodAccessor89.invoke(Unknown Source)
    2008-09-12 11:45:11,140 ERROR [STDERR]      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    2008-09-12 11:45:11,140 ERROR [STDERR]      at java.lang.reflect.Method.invoke(Method.java:585)
    2008-09-12 11:45:11,140 ERROR [STDERR]      at org.jboss.invocation.Invocation.performCall(Invocation.java:359)
    2008-09-12 11:45:11,140 ERROR [STDERR]      at org.jboss.ejb.MessageDrivenContainer$ContainerInterceptor.invoke(MessageDrivenContainer.java:495)
    2008-09-12 11:45:11,140 ERROR [STDERR]      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:158)
    2008-09-12 11:45:11,140 ERROR [STDERR]      at org.jboss.ejb.plugins.MessageDrivenInstanceInterceptor.invoke(MessageDrivenInstanceInterceptor.java:116)
    2008-09-12 11:45:11,140 ERROR [STDERR]      at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:63)
    2008-09-12 11:45:11,140 ERROR [STDERR]      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:121)
    2008-09-12 11:45:11,140 ERROR [STDERR]      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:350)
    2008-09-12 11:45:11,140 ERROR [STDERR]      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:181)
    2008-09-12 11:45:11,140 ERROR [STDERR]      at org.jboss.ejb.plugins.RunAsSecurityInterceptor.invoke(RunAsSecurityInterceptor.java:109)
    2008-09-12 11:45:11,140 ERROR [STDERR]      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:205)
    2008-09-12 11:45:11,140 ERROR [STDERR]      at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:138)
    2008-09-12 11:45:11,140 ERROR [STDERR]      at org.jboss.ejb.MessageDrivenContainer.internalInvoke(MessageDrivenContainer.java:402)
    2008-09-12 11:45:11,140 ERROR [STDERR]      at org.jboss.ejb.Container.invoke(Container.java:960)
    2008-09-12 11:45:11,140 ERROR [STDERR]      at sun.reflect.GeneratedMethodAccessor88.invoke(Unknown Source)
    2008-09-12 11:45:11,140 ERROR [STDERR]      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    2008-09-12 11:45:11,140 ERROR [STDERR]      at java.lang.reflect.Method.invoke(Method.java:585)
    2008-09-12 11:45:11,140 ERROR [STDERR]      at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
    2008-09-12 11:45:11,140 ERROR [STDERR]      at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
    2008-09-12 11:45:11,171 ERROR [STDERR]      at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
    2008-09-12 11:45:11,171 ERROR [STDERR]      at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
    2008-09-12 11:45:11,171 ERROR [STDERR]      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
    2008-09-12 11:45:11,171 ERROR [STDERR]      at org.jboss.invocation.local.LocalInvoker$MBeanServerAction.invoke(LocalInvoker.java:169)
    2008-09-12 11:45:11,171 ERROR [STDERR]      at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:118)
    2008-09-12 11:45:11,171 ERROR [STDERR]      at org.jboss.invocation.InvokerInterceptor.invokeLocal(InvokerInterceptor.java:209)
    2008-09-12 11:45:11,171 ERROR [STDERR]      at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:195)
    2008-09-12 11:45:11,171 ERROR [STDERR]      at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:61)
    2008-09-12 11:45:11,171 ERROR [STDERR]      at org.jboss.ejb.plugins.inflow.MessageEndpointInterceptor.delivery(MessageEndpointInterceptor.java:263)
    2008-09-12 11:45:11,171 ERROR [STDERR]      at org.jboss.ejb.plugins.inflow.MessageEndpointInterceptor.invoke(MessageEndpointInterceptor.java:140)
    2008-09-12 11:45:11,171 ERROR [STDERR]      at org.jboss.proxy.ClientMethodInterceptor.invoke(ClientMethodInterceptor.java:74)
    2008-09-12 11:45:11,171 ERROR [STDERR]      at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:100)
    2008-09-12 11:45:11,171 ERROR [STDERR]      at $Proxy73.execute(Unknown Source)
    2008-09-12 11:45:11,171 ERROR [STDERR]      at org.jboss.resource.adapter.quartz.inflow.QuartzJob.execute(QuartzJob.java:57)
    2008-09-12 11:45:11,171 ERROR [STDERR]      at org.quartz.core.JobRunShell.run(JobRunShell.java:203)
    2008-09-12 11:45:11,171 ERROR [STDERR]      at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
    2008-09-12 11:45:11,171 INFO [STDOUT] USer flag ..[Ljava.lang.String;@115c6cb                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    as i am writing the message failure details to a template...
         //on failure to send messages , reply to the sender about the failure
                                                                strBuff= tempDetail.writeToTemplate(smsmsg);     
    is that bcoz i am getting an exception

  • Problem in Mail deletion in POP3

    Hi
    I am using Pop3.
    I opened folder using
    folder.open (Folder.READ_WRITE);
    setting flag for deletion
    mimeMessages.setFlag (Flags.Flag.DELETED, true);
    then in finally block closing the folder
    if (mailbox.isConnected ()) {
    if(folder != null && folder.isOpen()) {
    try {
    folder.close (true);
    sometimes it is not deleting the messages.
    Please suggest something.
    Thanks
    Atal

    I am sorry but what do u mean by this? can u please explain in detail.
    actually most of times it works fine but in few cases mail deletion is failing.
    In my code: after folder.close (true); I just take a dump that comes successfully.
    The MailBox folder has been closed after deleting the ToBeDeleted Mails, if any, by folder.close method.
    MessageId of 1 th message which has been marked for Deletion : 1150475083.23686.prod-util-1.aspdeploy.com,S=57857
    MessageId of 2 th message which has been marked for Deletion : 1150475117.23813.prod-util-1.aspdeploy.com,S=6808
    MessageId of 3 th message which has been marked for Deletion : 1150475120.23818.prod-util-1.aspdeploy.com,S=9425
    MessageId of 4 th message which has been marked for Deletion : 1150475140.23852.prod-util-1.aspdeploy.com,S=6121
    these 4 messages were marked for deletion.
    then close called. after
    The MailBox folder has been closed after deleting the ToBeDeleted Mails, if any, by folder.close method.
    message, it again tries to retrieve the folder with messages
    Retrieving messages for mailbox ..
    MessageId of the: 1 th message is 1150475083.23686.prod-util-1.aspdeploy.com,S=57857
    MessageId of the: 2 th message is 1150475117.23813.prod-util-1.aspdeploy.com,S=6808
    MessageId of the: 3 th message is 1150475120.23818.prod-util-1.aspdeploy.com,S=9425
    MessageId of the: 4 th message is 1150475140.23852.prod-util-1.aspdeploy.com,S=6121
    MessageId of the: 5 th message is 1150475338.13255.prod-util-2.aspdeploy.com,S=7458
    MessageId of the: 6 th message is 1150475387.13339.prod-util-2.aspdeploy.com,S=6394
    MessageId of the: 7 th message is 1150475393.13357.prod-util-2.aspdeploy.com,S=59238
    MessageId of the: 8 th message is 1150475553.13615.prod-util-2.aspdeploy.com,S=86236
    first 4 messages are same which were not deleted.
    I have just attached the code. If you want to have a look then plz.
    thanks
    atal
    package com.deploy.email;
    import com.baltimore.jpkiplus.vaults.Vault;
    import com.baltimore.jpkiplus.x509.JCRYPTO_X509Certificate;
    import com.baltimore.jsmt.smime.JSMTException;
    import com.baltimore.jsmt.smime.SMIMEv2;
    import com.deploy.email.api.EmailException;
    import com.deploy.email.api.InitException;
    import com.deploy.email.api.ReceivedMessage;
    import com.deploy.email.config.LogicalMailboxConfiguration;
    import com.deploy.email.config.MailConfiguration;
    import com.deploy.email.config.PhysicalMailboxConfiguration;
    import com.deploy.email.util.SecureEmailHelper;
    import com.sun.mail.pop3.POP3Folder;
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.BufferedReader;
    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;
    import java.util.ArrayList;
    import java.util.Enumeration;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Vector;
    import javax.mail.Address;
    import javax.mail.AuthenticationFailedException;
    import javax.mail.Flags;
    import javax.mail.Folder;
    import javax.mail.Message;
    import javax.mail.MessagingException;
    import javax.mail.Multipart;
    import javax.mail.Part;
    import javax.mail.Store;
    import javax.mail.UIDFolder;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    import javax.naming.NamingException;
    import org.apache.log4j.Logger;
    * This class spawns a thread for each mailbox and pulls messages from those mailboxes at a specified interval.
    * Use start to initialize and stop to end the threads
    * Bug Fixes
    * - 8399 Broke out the mailServer into two separate potential servers; sendMailServer and receiveMailServer
    * This class was updated to reflect the receiveMailServer setting
    * 04/25/03 John Gemski
    * - 10619 Added support for the Lotus Notes Client as per the 3.x fix. Copied logic from 3.x as detailed
    * by Hari in the bug report
    * 08/13/03 John Gemski
    * - Added Email Client Calendaring support - John Gemski 10/21/2003
    * @see com.deploy.email.EmailChannel
    public class RetrieveMail implements Runnable {
    /** Used to tell the threads when to stop */
    private static boolean keepRunning=true;
    //anish For nationwide
    private int maximumsizeofinbox=-1;
    /** The messages on the mail server that have been pulled but not deleted */
    private HashMap messagesOnServer;
    /** These are the mailbox types. Will only be one here for the Azetra impl */
    private static List logicalMailboxes;
    /** The list of running threads. Need to be tracked so they can be interrupted upon stop */
    private static ArrayList receiveThreads;
    /** A reference to the EmailChannel object, which may contain updated information. */
    private static EmailChannel emailChannel = EmailChannel.getInstance();
    private static Logger log = Logger.getLogger(EmailChannel.LOGGER_MODULE_NAME);
    // Thread variables
    /** the configuration for the physical mailbox from which the emails are being pulled. */
    private PhysicalMailboxConfiguration tPhysicalMailbox;
    /** the logical type (OLJB, ScanWorld, Task Response, Resume) that the physical mailbox thread is pulling for */
    private String tLogicalType;
    /** JavaMail Store */
    private Store mailbox;
    // Acceptable Protocols to retrieve mail from the mail server.
    public static final int RECEIVE_MAIL_PROTOCOL_POP3 = 0;
    public static final int RECEIVE_MAIL_PROTOCOL_IMAP = 1;
    public static final int NUM_RECEIVE_MAIL_PROTOCOLS = 2;
    public static String [] RECEIVE_MAIL_PROTOCOL_NAME;
    /** Indicates whether or not the Secure Email feature is enabled. */
    private static boolean secureEmailEnabled =false;
    static {
    RECEIVE_MAIL_PROTOCOL_NAME = new String [NUM_RECEIVE_MAIL_PROTOCOLS];
    RECEIVE_MAIL_PROTOCOL_NAME [RECEIVE_MAIL_PROTOCOL_POP3] = "pop3";
    RECEIVE_MAIL_PROTOCOL_NAME [RECEIVE_MAIL_PROTOCOL_IMAP] = "imap";
    // FIX for socket hang issue (FIX PR 14253) while processing the mail
    public static final String SOCKET_READ_ERROR = "No inputstream from datasource";
    /** Constructor for new RetrieveMail thread.
    * @param phys_config the mailbox configuration for a specific physical mailbox (i.e. [email protected])
    * @param logical_type the logical type for this mailbox ("Resumes", "OLJB", "ScanWorld", or "TaskResponse")
    private RetrieveMail(PhysicalMailboxConfiguration phys_config, String logical_type) {
    this.tPhysicalMailbox = phys_config;
    this.tLogicalType = logical_type;
    * Retrieve email messages from a mail server for the particular physical mailbox indicated with the thread
    * @throws EmailException if any fatal error occurs with the retrieval or processing of the incoming emails
    private void retrieveMessages () throws EmailException {
    Vector msgVector = new Vector ();
    Vector deleteMsgVector = new Vector ();
    ReceivedMessage [] recMessages;
    MailConfiguration mailConfig = emailChannel.getMailConfiguration();
    long maxReceivedEmailSize = mailConfig.getMaximumReceiveSize();
    //Anish for Bug 20366 for Nationwide Patch 06
    maximumsizeofinbox = mailConfig.getMaximumsizeofinbox();
    // Synchronize on the mailbox object for the mailbox from which we
    // are going to retrieve messages. We don't want more than one
    // thread connected to a mailbox at a time, but we don't want to
    // prevent multiple different threads from being connected to
    // multiple different mailboxes simultaneously.
    synchronized (mailbox) {
    boolean throwingException = false;
    Folder folder = null;
    try {
    /* Fix for 8399 - use the getReceiveMailServer call instead of the
    * getMailServer call
    // Connect to the server for receiving mail.
    mailbox.connect (mailConfig.getReceiveMailServer(),
    tPhysicalMailbox.getMailboxName(),
    tPhysicalMailbox.getMailboxPassword());
    // We are only interested in the "INBOX" folder.
    folder = mailbox.getFolder ("INBOX");
    // Open with write permissions as well, so we can delete messages from the server
    folder.open (Folder.READ_WRITE);
    // Anish for Bug 20366 for Nationwide Patch 06
    //int numMessages = folder.getMessageCount ();
    int numMessages1 = folder.getMessageCount ();
    int numMessages = 0;
    //log.info("Anish123 " + maximumsizeofinbox);
    if (maximumsizeofinbox < 0)
    numMessages = numMessages1;
    else
              if (numMessages1 > maximumsizeofinbox) {
              numMessages = maximumsizeofinbox;
              //log.info("Anish try 1 " + numMessages1);
              else {
              numMessages = numMessages1;
              //log.info("Anish try 2 " + numMessages);
    //     log.info("Anish try 4 " + numMessages);
    // End by anish
    if (numMessages > 0) { // There are messages to retrieve
    Message [] messagesRaw = folder.getMessages ();
    // We need to cast the messages to MIME message objects so
    // that we can access some MIME message-specific functionality.
    MimeMessage [] mimeMessages = new MimeMessage [numMessages];
    for (int i = 0; i < numMessages; i++) {
    mimeMessages = (MimeMessage) messagesRaw [i];
    // We can only get messages totalling maxReceivedMessageSize bytes.
    // Calculate how many messages we may get and still stay under the limit.
    int numMessagesToRetrieve = 0;
    int i = 0;
    if( maxReceivedEmailSize > 0) {
    int totalSize = 0;
    numMessagesToRetrieve = 0;
    boolean reachedLimit = false;
    while ((i < numMessages) && !reachedLimit) {
    int messageSize = mimeMessages[i].getSize ();
    int newTotalSize = totalSize + messageSize;
    if (newTotalSize > maxReceivedEmailSize) {
    //if this is the first message then break out and process it
    if( i == 0 ) {
    i++;
    totalSize = newTotalSize;
    reachedLimit = true;
    else {
    totalSize = newTotalSize;
    i++;
    numMessagesToRetrieve = i;
    i = 0;
    else {
    numMessagesToRetrieve = mimeMessages.length;
    while( i < numMessagesToRetrieve )
    boolean gotMessage = false;
    String uniqueID = null;
    if( numMessagesToRetrieve > 0 ) {
    // Get the ID for the message
    uniqueID = getUniqueID (mimeMessages[i], folder);
    //By Anurag for Req#2907 to add Debugging Logs start
    log.info("MessageId of the: " + (i+1) + " th message is " + uniqueID);
    //By Anurag for Req#2907 to add Debugging Logs End
    // Check if we have previoiusly retrieved this message.
    Object value = messagesOnServer.get (uniqueID);
    gotMessage = (value != null);
    if (!gotMessage) { // Make sure message is filled in.
    boolean processMessage = true;
    try {
    if(secureEmailEnabled) {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    mimeMessages[i].writeTo(os);
    InternetAddress[] senders = (InternetAddress[])mimeMessages[i].getFrom();
    InternetAddress[] recipients = (InternetAddress[])mimeMessages[i].getRecipients (Message.RecipientType.TO);
    Exception lastException = null;
    Vault v = null;
    for (int countRecipients = 0; countRecipients < recipients.length; countRecipients++) {
    lastException = null;
    v = null;
    // try to get the recipient's address from the Vault hash table
    log.info("Trying to get Vault for address: " + recipients[countRecipients].getAddress ());
    v = SecureEmailHelper.getVault (recipients[countRecipients].getAddress ());
    // we can't decrypt if we don't have a private key from the vault!
    if (v == null) {
    log.info("The PFX file for the email account: " + recipients[countRecipients].getAddress () + " is not found or invalid. Please correct.");
    lastException = new EmailException(EmailException.REASON_UNKNOWN, "The PFX file for the email account: " + recipients[countRecipients].getAddress () + " is not found or invalid. Please correct.");
    else {
    break;
    // if we came out with all exceptions, throw the last one we received.
    if (lastException != null) {
    log.error(lastException.getMessage(), lastException);
    throw lastException;
    SMIMEv2 smimer = new SMIMEv2(v);
    // Set up input and output streams to read an S/MIME message
    byte[] originalMessageBytes = os.toByteArray();
    String origMessStr = new String(originalMessageBytes);
    // The SMIMEv2 can't handle extra characters.
    // Noticed that messages contained an "+OK", which was causing problems
    // removed the entire line
    if(origMessStr.startsWith("+OK")) {
    int index = origMessStr.indexOf("\n");
    origMessStr = origMessStr.substring(index+1);
    byte[] revMessageStr = origMessStr.getBytes();
    ByteArrayInputStream input_source = new ByteArrayInputStream(revMessageStr);
    ByteArrayOutputStream output_sink = null;
    boolean smimeRecognized=true;
    boolean wasSigned=false;
    boolean wasEncrypted=false;
    // Making changes to reflect Baltimore's suggestion about layers
    ByteArrayInputStream newMessage = null;
    boolean done=false;
    // According to Baltimore, there can be two layers of encryption
    // inner and outer. It could be encrypted & signed, with it being either
    // encrypted on the outer layer and signed on the inner, or vice versa.
    // We want to ensure that this loop breaks out after either
    // 1. there were 2 layers sign/encrypted or encrypted/signed
    // 2. there was an error
    int layers=0;
    while(!done && layers < 2) {
    output_sink = new ByteArrayOutputStream();
    layers++;
         try {
    // This step must be don't before any cryptographic operations. It lets the SMIMEv2 class
    // figure out what it has as an input and where to place the output
    smimer.attachStreams(input_source, true, output_sink, false, false);
    catch (JSMTException jse) {
    // This is common since unencrypted and unsigned data cannot perform this function
    // Ideally, Baltimore says to use the type SMIMEv2.TYPE_DATA, but it never gets this
    // far since this fails.
    // We will skip the attempts to decrypt/verify the signature, since we know we won't
    // be able to interpret what type of message it is.
    smimeRecognized=false;
    // Will only be one layer
    done=true;
         log.debug("SMIME recognized: " + smimeRecognized);
    if(smimeRecognized) {
    // Get the S/MIME message type
    int nextdata = smimer.getMessageType();
    log.info("SMIME message type: " + nextdata);
    if (nextdata == smimer.TYPE_SIGNED) { // Signed message
    wasSigned=true;
    boolean matchedSender = false;
    // Didn't know you could have multiple "from" in an email address
    // Right now, only one of the "froms" has to have a certificate
    for(int s=0; s < senders.length; s++) {
    // get the sender's address
    String from_sender = senders[s].getAddress();
    try {
    // retrieve the certificates from the LDAP
    JCRYPTO_X509Certificate[] senderCerts = null;
    senderCerts = SecureEmailHelper.getCertificatesFromLDAP(from_sender);
    if(senderCerts!=null) {
    // verify() needs to take in a chain of certificates
    com.baltimore.jsmt.pkcs7.CertificateChain cc= new com.baltimore.jsmt.pkcs7.CertificateChain();
    // create certificate chain
    for(int k=0; k < senderCerts.length; k++) {
    cc.addCertificate(senderCerts[k]);
    // verify the Certificate Chain against the message's certs
    if(smimer.verify(cc)) {
    // found a match, the message was verified
    matchedSender=true;
    break;
    else
    log.error("Could not verify the sender" + from_sender);
    done=true;
    catch(NamingException ne) {
    log.error("There was a problem connecting to the LDAP for " + from_sender,ne);
    done=true;
    // if none of the senders matched, we need to not process
    // the email message, since it will be unreadable
    if(!matchedSender) {
    StringBuffer sendString = new StringBuffer();
    for(int s=0; s < senders.length; s++) {
    String from_sender = senders[s].getAddress();
    sendString.append(" : " );
    sendString.append(from_sender);
    processMessage = false;
    log.error("Could not find certificate for any of the senders" + sendString.toString());
    done=true;
    else if (nextdata == smimer.TYPE_ENVELOPED) { // Encrypted message
    log.debug("SMIME Encrypted message!");
    wasEncrypted = true;
    try {
    log.debug("SMIME Decrypting message...");
    // Decrypts the message
    smimer.openEnvelope();
    catch (JSMTException jse) {
    // Could not decrypt message
    log.error("Could not decrypt message: " + jse.getMessage (), jse);
    processMessage = false;
    done=true;
    else {
    log.debug("Unrecognized type");
    // doesn't seem to get here since Baltimore toolkit doesn't accept
    // nonencrypted, nonsigned emails (it should though). Keep here for future
    // releases of the toolkit
    done = true;
    // Now that we have output_sink,
    // retrieve the bytes
    byte[] processedBytes = output_sink.toByteArray();
    newMessage = new ByteArrayInputStream(processedBytes);
    input_source = new ByteArrayInputStream(processedBytes);
    else {
    // only for the first time around, revert to original
    if(layers==1) {
    // Keep original message
    newMessage = new ByteArrayInputStream(revMessageStr);
    log.debug("wasSigned: " + wasSigned + " wasEncrypted: " + wasEncrypted);
    // create the mime message again
    mimeMessages[i] = new MimeMessage(emailChannel.getSession(),newMessage);
    mimeMessages[i].setFrom (senders[0]);
    mimeMessages[i].setRecipients (Message.RecipientType.TO, recipients);
    // decrypted/verified data is automatically written to output_sink
    input_source.close();
    output_sink.close();
    // If the message wasn't signed, we can still process the message
    // if the settings allow the server to process unsigned messages
    // If not, set the flag to not process this message
    if(!tPhysicalMailbox.getAcceptUnsignedEmail() && !wasSigned) {
         log.info("Server configuration does not allow unsigned emails.");
    processMessage = false;
    // If the message wasn't encrytped, we can still process the message
    // if the settings allow the server to process unencrypted messages
    // If not, set the flag to not process this message
    if(!tPhysicalMailbox.getAcceptUnencryptedEmail() && !wasEncrypted) {
    log.info("Server configuration does not allow unencrypted emails.");
    processMessage = false;
    if(processMessage) {
    MimeMessage m = mimeMessages[i];
    if( maxReceivedEmailSize > 0 && m.getSize() > maxReceivedEmailSize ) {
    try {
    m = constructDummyMsg( m, m.getSize() );
    catch (Exception e) {
    // Add message to a list of messages to be deleted after
    // finished retrieving messages.
    deleteMsgVector.addElement (uniqueID);
    ReceivedMessage receivedMessage =
    new ReceivedMessage (m, uniqueID);
    msgVector.addElement (receivedMessage);
    else {
    log.info("Email could not be processed.");
    deleteMsgVector.addElement (uniqueID);
    catch (EmailException ee) {
    log.error("Email Exception", ee);
    deleteMsgVector.addElement (uniqueID);
    } // mail socket hang fix
    catch (javax.mail.MessagingException e) {
    String message = e.getMessage();
    // if it's a socket hang issue due to network outage, we want to logout and refetch the messages.
    if (message.equals(SOCKET_READ_ERROR)) {
    log.error("Socket timed out. Closing the connection", e);
    messagesOnServer.clear();
    throw new EmailException(

  • Problem with access to SMTP, IMAP, POP3 protocols in CAS 2013.

    Hi,
    we have problem with access thgrough SMTP, IMAP, POP3 protocols in CAS 2013.
    If I test connection to SMTP 25 port from other computer, session end quickly.
    Test from CAS2013 to localhost or public IP is OK (similar also for IMAP and POP3).
    Receive connectors are with defaults settings, firewall is disabled.
    Service Microsoft Frontend Transport Services restarted, but no success.
    Certificate is assigned to IMAP, POP3, SMTP, IIS.
    IIS and HTTP(s), protocols are OK. Clients can connects only thgrough web, mobile (ActiveSync), or with Outlook with proxy.
    Do you have some tip, what to test?
    If I create new testing receive connector on port 26 for anonymous, behaviour is same, quick disconnecting.
    Thank's Mirek

    Hi,
    Pleaser try to use the following link to test your STMP/POP/IMAP e-mail, and check the test if successful:
    https://testconnectivity.microsoft.com/
    If unsuccessful, please check the test result, it will tell us what caused the problem.
    Thanks.
    Niko Cheng
    TechNet Community Support

Maybe you are looking for

  • How can I import ALL of my files from my iPod Touch to iTunes?

    My laptop recently caught a virus and I had to reformat the hardive meaning losing my iTunes library.  I still have everthing on my iPod and an external hard drive.  I've already tried the transfer purchases button which did just that, transfer my do

  • Windows 8 and LR tethering issue with D7000

    I just purchased a new Lenovo W20 laptop with Windows 8 pro, installed LR and PS6. All of this is up to date on patches. I tried to tether my Nikon D7000 to a USB 2.0 and USB 3 port and have the same issue... LR sees the D7000 and lists it in the tet

  • I've lost the use of predictive text in the subject line of gmail and I want to get it back

    I used to be able to hit a few characters in the subject line of a gmail compose window and it would bring up past subject lines with the same characters. That doesn't work anymore. How do I get it back? I've tried changing the settings under prefere

  • Reports exported to Excel - Formatting issues

    We have two Business Objects Enterprise servers (boxi r2 and boxi r3.1 sp3) running side by side.  We find that reports created using boxi r2 and exported to Excel format look fine.  When we run the same report and export to excel using boxi r3.1 sp3

  • Strange error in explicit instance creation

    Dear all, using NW2004s I have a strange error while explicit instance creation: Let´s say I have a class a in the Class Builder calles c1. With method "check_data". In my program I do the following: DATA: ref_chk TYPE REF TO object. create object re