-1
好的,那我该如何导入JavaMail呢?我已经阅读了至少15个有关如何解决这个问题的不同想法,并尝试将javax.mail.jar移动到我的导出列表顶部等等。显然,一个ClassNotFoundException正在抛出启动一个新的会话,并根据我读过的所有其他职位,它应该工作。这里是我的代码:正确导入JavaMail
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", "[email protected]", "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");
}
}
}