3 Replies Latest reply: Apr 5, 2011 6:02 PM by 823071 RSS

    How to copy sent messages to an IMAP server

    823071
      Hello everyone,

      I am looking for a way to copy messages, which have been sent through a SMTP server, to a dedicated folder on an IMAP server.

      So far I tried this:

      MimeMessage message = new MimeMessage(smtpSession);
      // (...) Set up fields subject, to, cc, bcc, etc...
      sendMessage(message); // Works!
      Folder sourceFolder = message.getFolder(); // Returns null of course :-(
      Message[] messages = new Message[1];
      messages[0] = message;
      sourceFolder.copyMessages(messages, destinationFolder); // Nullpointer exception here because message has no parent folder
      // (destinationFolder is an IMAP folder on an IMAP server with working connection)

      No luck so far because the code above fails due to a nullpointer exception.

      Is there a way to somehow get this done?