0

I am generating emails using Spring JavaMail and Velocity Template to send to the customer.I have to store these outgoing Emails into some folder in .MSG format.I did so much research on the web.But not able to find right Java API to do this.And in Spring Java Mail I am not able to find writeTO() method which is in JavaX.mail API.Can some one help me with this issue.

SRy
  • 2,901
  • 8
  • 36
  • 57

1 Answers1

1

You already found that javax.mail.Part has a writeTo method.

So what you need is a way to "convert" a spring simple mail to an javax.mail

It should work more or less this way:

org.springframework.mail.javamail.MimeMailMessage message 
message = new MimeMailMessage(new SmartMimeMessage(getSession(),
           getDefaultEncoding(),
           getDefaultFileTypeMap()));
yourSimpleMessage.copyTo(message);

javax.mail.internet.MimeMessage result = message.getMimeMessage());

result.writeTo(yourOutputStream);
Ralph
  • 118,862
  • 56
  • 287
  • 383
  • @Ralph.......great it's working..Thanks alot you saved my lot of time.Now i am saving my message as .msg which i have given in writeTo("c:\temp\sample.msg") directly.Is this the right way to create .msg file?Cause I am not able to Open this after creating this file.And attachments are coming like "JVBERi0xLjQKJe" random charaters.... – SRy Sep 05 '12 at 18:02
  • The file you're creating is a MIME format file, which is usually called a ".eml" file. A .msg file uses the Microsoft-proprietary format; I'm not aware of any Java code to write such files. Maybe we should ask what you plan to do with the files after you've written them? Perhaps you should be storing them in a folder in your mail server instead? – Bill Shannon Sep 05 '12 at 19:16