1

我努力了

ft = new FlagTerm(new Flags(Flags.Flag.ANSWERED), false);

从收件箱中获取未答复的邮件列表,但从收件箱返回所有邮件。

message.isSet(Flags.Flag.ANSWERED);

也给出相同的输出。

如何列出收件箱中已读但未回复的邮件?

4

2 回答 2

0

你在使用 IMAP 吗?如果没有,这将不起作用。

当您回复该消息时,由邮件阅读器在该消息上设置 ANSWERED 标志。一些邮件阅读器可能不会这样做。你用的是什么邮件阅读器?

于 2013-03-07T21:03:45.867 回答
0

下载 JavaMail API 并确保相关的 jar 文件在您的类路径中。

使用 gmail.com Web 界面,您需要将设置阻止更改为未阻止到 gmail 帐户。导入 java.util。; 导入 javax.mail。; 导入 javax.mail.internet.*;

公共类主要{

private static String USER_NAME = "*****";  // GMail user name (just the part before "@gmail.com")
private static String PASSWORD = "********"; // GMail password
private static String RECIPIENT = "lizard.bill@myschool.edu";

public static void main(String[] args) {
    String from = USER_NAME;
    String pass = PASSWORD;
    String[] to = { RECIPIENT }; // list of recipient email addresses
    String subject = "Java send mail example";
    String body = "Welcome to JavaMail!";

    sendFromGMail(from, pass, to, subject, body);
}

private static void sendFromGMail(String from, String pass, String[] to, String subject, String body) {
    Properties props = System.getProperties();
    String host = "smtp.gmail.com";
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.host", host);
    props.put("mail.smtp.user", from);
    props.put("mail.smtp.password", pass);
    props.put("mail.smtp.port", "587");
    props.put("mail.smtp.auth", "true");

    Session session = Session.getDefaultInstance(props);
    MimeMessage message = new MimeMessage(session);

    try {
        message.setFrom(new InternetAddress(from));
        InternetAddress[] toAddress = new InternetAddress[to.length];

        // To get the array of addresses
        for( int i = 0; i < to.length; i++ ) {
            toAddress[i] = new InternetAddress(to[i]);
        }

        for( int i = 0; i < toAddress.length; i++) {
            message.addRecipient(Message.RecipientType.TO, toAddress[i]);
        }

        message.setSubject(subject);
        message.setText(body);
        Transport transport = session.getTransport("smtp");
        transport.connect(host, from, pass);
        transport.sendMessage(message, message.getAllRecipients());
        transport.close();
    }
    catch (AddressException ae) {
        ae.printStackTrace();
    }
    catch (MessagingException me) {
        me.printStackTrace();
    }
}

}

于 2015-01-23T07:25:37.363 回答