javaemlpst

How to Convert EMLs to PST?


Do any one have the solution that how can I convert my EMLs to PST. I have searched a lot and couldn't find any suitable solution for JAVA..


Solution

  • Hi as I can see you are trying to read emls and then put them to a PST,

    You can use Aspose.Email for that

    but for reading EML you can use java mail API.

    for example:

    import java.io.*;
    import java.util.*;
    
    import javax.mail.*;
    import javax.mail.internet.*;
    
    public class EML {
    
      public static void main(String args[]) throws Exception {
    
      String host = "192.168.10.205";
      String from = "test@localhost";
      String to = "test@localhost";
    
      Properties props = System.getProperties();
      props.setProperty("mail.smtp.host", host);
      props.put("mail.transport.protocol", "smtp");
    
      Session mailSession = Session.getDefaultInstance(props, null);
    
      File emlFile = new File("message.eml");
      InputStream source = new FileInputStream(emlFile);
    
      MimeMessage message = new MimeMessage(mailSession, source);
    
      System.out.println("Subject : " + message.getSubject());
      System.out.println("From : " + message.getFrom()[0]);
      System.out.println("--------------");
      System.out.println("Body : " + message.getContent());
      }
    }
    

    for adding PST using Aspose.Email

    PersonalStorage pst = PersonalStorage.create(dir + "archive.pst", 0);
    // create a folder at the root of PST
    pst.getRootFolder().addSubFolder("Inbox");
    // add message to newly created folder
    pst.getRootFolder().getSubFolder("Inbox").addMessage(MapiMessage.fromFile(dir + "my.eml"));
    

    Hoping this will help you

    Happy Coding