通过JavaMail读取POP3消息仅返回html

时间:2016-01-24 01:17:29

标签: javamail message pop3

通过JavaMail读取POP3消息只返回html

所以我问我如何指定回报? 意味着返回messagefrom,messagedate和messagebody

如何将我的结果放在标签或textarea上

请某人帮助我

import java.util.Properties;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Store;
import java.awt.*;
import javax.swing.*;

public class Receiver {

  public static void main(String[] args) throws Exception {

    Properties props = new Properties();

    String host = "mail.newhoster.org";
    String username = "admin@newhoster.org";
    String password = "I_hffngh12";
    String provider = "pop3";

    Session session = Session.getDefaultInstance(props, null);
    Store store = session.getStore(provider);
    store.connect(host, username, password);

    Folder inbox = store.getFolder("INBOX");
    if (inbox == null) {
      System.out.println("No INBOX");
      System.exit(1);
    }
    inbox.open(Folder.READ_ONLY);

    Message[] messages = inbox.getMessages();
    for (int i = 0; i < messages.length; i++) {
      System.out.println("Message " + (i + 1));
      messages[i].writeTo(System.out);
      String olm = messages[i].getSubject();
      System.out.println(olm);
//      JFrame fa = new JFrame();
//      fa.setBounds(20, 20, 300, 200);
//      JLabel lb = new JLabel("hello every ");
//      fa.add(lb);
//      lb.setPreferredSize(new Dimension(100,100));
//      lb.setBackground(Color.red);
//      
//      fa.setVisible(true);
    }
    inbox.close(false);
    store.close();
  }
}

1 个答案:

答案 0 :(得分:1)

您需要阅读JavaMail FAQ并查看JavaMail sample programs以了解如何使用JavaMail API访问邮件内容。请注意,您无法控制邮件是否包含html,发件人控制邮件的内容。如果您收到仅包含html内容的消息而您不想将其显示为html,则需要自己将其转换为其他格式; JavaMail对此没有帮助。