Loading .eml files into javax.mail.Messages

后端 未结 2 471
眼角桃花
眼角桃花 2021-01-12 11:35

I\'m trying to unit test a method which processes javax.mail.Message instances.

I am writing a converter to change emails which arrive in different form

2条回答
  •  半阙折子戏
    2021-01-12 11:49

    After a few tests, I finally successfully loaded a message using the MimeMessage(Session, InputStream) public constructor (as opposed to the Folder-based protected one cited in the other response).

    import java.io.FileInputStream;
    import java.io.InputStream;
    
    import javax.mail.internet.MimeMessage;
    
    public class LoadEML {
    
        public static void main(String[] args) throws Exception {
            InputStream is = new FileInputStream(args[0]);
            MimeMessage mime = new MimeMessage(null, is);
            System.out.println("Subject: " + mime.getSubject());
        }
    
    }
    

提交回复
热议问题