好的,那我该如何导入JavaMail?我已经阅读了至少15个关于如何解决此问题的不同想法,并尝试将javax.mail.jar移动到导出列表的顶部,依此类推。显然,正在抛出一个ClassNotFoundException来启动一个新的Session,并且根据我读过的所有其他帖子,它应该可以工作。这是我的代码:
package y.mail;
import java.awt.BorderLayout;
import java.awt.Color;
import java.util.Properties;
import javax.mail.Folder;
import javax.mail.Session;
import javax.mail.Store;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class MailReader extends JFrame {
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
new MailReader();
}
public MailReader() {
this.setSize(800, 500);
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setLayout(new BorderLayout());
this.setTitle("MailReader");
JTextArea area = new JTextArea();
area.setEditable(false);
area.setForeground(Color.GREEN);
area.setBackground(Color.BLACK);
this.add(new JScrollPane(area),BorderLayout.CENTER);
this.setVisible(true);
area.append("Attempting to access inbox..\n");
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
try {
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect("imap.googlemail.com", "myemailid@gmail.com", "password");
Folder f = store.getFolder("INBOX");
area.append("Connected to inbox!");
area.append(f.getMessageCount() + "");
} catch (Exception e) {
area.append("===========Error===========\n");
area.append(e.getStackTrace() + "\n");
}
}
}