问题描述
- Java Mail API新的应用程序接口在哪里下载
-
/*- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
/
package usepop3client;
import javax.mail.;
import javax.mail.internet.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
/**
*- @author Administrator
*/
public class UsePOP3Client extends JFrame{
JButton receiveButton=new JButton("收信");
JLabel popServerLabel=new JLabel("POP3服务器:");
JLabel usernameLabel=new JLabel("用户名:");
JLabel passwordLabel=new JLabel("密码:");
JTextField popServerField=new JTextField(40);
JTextField usernameField=new JTextField(40);
JPasswordField passwordField=new JPasswordField(40);
JTextArea messageField=new JTextArea(10,10);
JScrollPane jsp=new JScrollPane(messageField);
public UsePOP3Client(){
Container contentPane=this.getContentPane();
JPanel labels=new JPanel(new GridLayout(3,1));
JPanel fields=new JPanel(new GridLayout(3,1));
labels.add(popServerLabel);fields.add(popServerField);
labels.add(usernameLabel);fields.add(usernameField);
labels.add(passwordLabel);fields.add(passwordField);
Box north=Box.createHorizontalBox();
north.add(labels);north.add(fields);
contentPane.add(north,"North");contentPane.add(jsp,"Center");
JPanel south=new JPanel();
south.add(receiveButton);
receiveButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
receive(popServerField.getText(),usernameField.getText(),passwordField.getText());
}
});
contentPane.add(south,"South");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("收电子邮件");
setSize(400,400);
setVisible(true);
}
public void receive(String popServer,String popUser,String popPassword){
Store store=null;
Folder folder=null;
try{
Properties props=System.getProperties();
Session session=Session.getDefaultInstance(props,null);
store=session.getStore("pop3");
store.connect(popServer,popUser.popPassword);
folder=store.getDefaultFolder();
if(folder==null)throw new Exception("No default folder");
folder=folder.getFolder("INBOX");
if(folder==null)throw new Exception("NO POP3 INBOX");
folder.open(folder.READ_ONLY);
Message[] msg=folder.getMessages();
for(int msgNum=0;msgNum<msg.length;msgNum++){
printMessage(msg[msgNum]);
}
}catch(Exception ex){ex.printStackTrace();}
finally{
try{
if(folder!=null)folder.close(false);
if(store!=null)store.close();
}catch(Exception ex){ex.printStackTrace();}
finally{
try{
if(folder!=null)folder.close();
if(store!=null)store.close();
}catch(Exception ex2){ex2.printStackTrace();}
}
}
}
public void printMessage(Message message){
try{
String from=((InternetAddress)message.getFrom()[0]).getPersonal();
if(from==null)from=((InternetAddress)message.getFrom()[0]).getAddress();
messageField.append("FROM:"+from+"n");
String subject=message.getSubject();
messageField.append("SUBJECT:"+subject+"n");
Part messagePart=message;
Object content=messagePart.getContent();
if(content instanceof Multipart){
messagePart=((Multipart)content).getBodyPart(0);
messageField.append("[Multipart Message]"+"n");
}
String contentType=messagePart.getContentType();
messageField.append("CONTENT:"+contentType+"n");
if(contentType.startsWith("text/plain")||contentType.startsWith("text/html")){
InputStream is=messagePart.getInputStream();
BufferedReader reader=new BufferedReader(new InputStreamReader(is));
String thisLine=reader.readLine();
while(thisLine!=null){
messageField.append(thisLine+"n");
thisLine=reader.readLine();
}
}
messageField.append("------------END-------------");
}catch(Exception ex){ex.printStackTrace();}
}/**
- @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Font font=new Font("JFrame",Font.PLAIN,14);
Enumeration keys=UIManager.getLookAndFeelDefaults().keys();
while(keys.hasMoreElements()){
Object key=keys.nextElement();
if(UIManager.get(key)instanceof Font)UIManager.put(key,font);
}
UsePOP3Client popClient=new UsePOP3Client();
}
- @param args the command line arguments
}
请大家看一下,包下面第一个和第二个导入类,我不知道在哪里下载,想请教一下大家下载的地址:javax.mail.*,javax.mail.internet.*。
解决方案
http://www.findjar.com/index.x
http://download.csdn.net/download/yufengzuolao/6688033
http://bbs.csdn.net/topics/40371363
http://bbs.csdn.net/topics/40280743
http://blog.csdn.net/xiaozi8112/article/details/39212691
这几个都有,你上面提到的都在同一个文件里的;
如果回答对你有帮助,请采纳
时间: 2024-09-30 01:31:58