欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

使用JavaMail解析EML文件,javamail解析eml,Java 当我们在ou

来源: javaer 分享于  点击 2405 次 点评:150

使用JavaMail解析EML文件,javamail解析eml,Java 当我们在ou


Java 当我们在outlook中保存一个邮件是可以存成eml格式,这种格式是标准的邮件格式. 这种文件可以用JavaMail来解析。

import java.util.*;import java.io.*;import javax.mail.*;import javax.mail.internet.*;public class ReadEmail {   public static void main(String args[]) throws Exception{       display(new File("C:\\temp\\message.eml"));   }   public static void display(File emlFile) throws Exception{        Properties props = System.getProperties();        props.put("mail.host", "smtp.dummydomain.com");        props.put("mail.transport.protocol", "smtp");        Session mailSession = Session.getDefaultInstance(props, null);        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());    }}

eml文件格式说明 :

None

通过上面的程序解析后的输出如下:

Subject : Example for HowToFrom : real gagnon --------------Body :This is an example for HowTo
相关栏目:

用户点评