如何使用 javax.mail 阅读邮件正文中的文本
2022-08-31 15:17:34
我正在开发一个使用javax.mail的客户端邮件来阅读邮箱内的邮件:
Properties properties = System.getProperties();
properties.setProperty("mail.store.protocol", "imap");
try {
Session session = Session.getDefaultInstance(properties, null);
Store store = session.getStore("pop3");//create store instance
store.connect("pop3.domain.it", "mail.it", "*****");
Folder inbox = store.getFolder("inbox");
FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
inbox.open(Folder.READ_ONLY);//set access type of Inbox
Message messages[] = inbox.search(ft);
String mail,sub,bodyText="";
Object body;
for(Message message:messages) {
mail = message.getFrom()[0].toString();
sub = message.getSubject();
body = message.getContent();
//bodyText = body.....
}
} catch (Exception e) {
System.out.println(e);
}
我知道该方法返回一个对象,因为内容可以是a,a,a和其他(我认为)...有没有办法始终获取消息正文中的文本?谢谢!!getContent()
String
MimeMultiPart
SharedByteArrayInputstream