• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JavaMail - Construct a MimeMessage from a text file

 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I've written some code that connects to the mail server, opens a certain inbox, retrieves the message(s) and writes them to an output stream. Limiting my code to that last bit:



So now, if I were to actually save each message to an individual text file, I'd get (according to the javadoc) "the message as an RFC 822 format stream".

I then tried to find the message.readFrom(InputStream is) method, and did not find one. There's something that looks promising on the MimeMultipart class (a parse() method) but it (and other methods like it) are all protected. So, I'm not very familiar with this API other than using it to send email. Does anyone know then, how to use it as if I were a mailserver, reading a mailfile off disk?

What I eventually want to do: Make an exact copy of a certain message that I've got in an inbox. This particular message, which is from an external 3rd party, exhibits problems for software further down the line that reads and deletes the message from the inbox. I'd simply like to be able to reliably re-produce this exact message with all its problems. I've had no success constructing my own messages using the JavaMail API, that duplicates the exact nature of this message (which is why I thought to make a copy of it).
 
Sheriff
Posts: 22787
131
Eclipse IDE Spring Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about the constructors of MimeMessage? You'll need a Session, but that shouldn't be a problem.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Talk about not seeing the tree for the forest.

Thanks, that works dandy.
 
reply
    Bookmark Topic Watch Topic
  • New Topic