- 浏览: 34715 次
- 性别:
- 来自: 北京
-
最新评论
-
12345678:
貌似明白了,谢谢。
swing 线程 -
山脚下的农民:
不错,有创意
java 浏览器1 -
ftp51423121:
很漂亮我是说
转:Https中安全正书导入到java的cacerts证书库中 -
xzs603:
说下原理!
转:Https中安全正书导入到java的cacerts证书库中
package com.email;
import javax.mail.*;
import javax.mail.internet.*;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JLabel;
import javax.swing.JList;
import java.util.*;
import java.awt.BorderLayout;
import javax.swing.JProgressBar;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.border.BevelBorder;
import javax.swing.border.LineBorder;
import javax.swing.border.SoftBevelBorder;
import java.awt.event.*;
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
/**
* <p>Title: 使用JavaMail接收邮件</p>
* <p>Description: 实例JavaMail包接收邮件,本实例没有实现接收邮件的附件。</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Filename: POPMail.java</p>
* @version 1.0
*/
public class POPMail extends javax.swing.JDialog implements WindowListener {
/**
*<br>方法说明:主方法,接收用户输入的邮箱服务器、用户名和密码
*<br>输入参数:
*<br>返回类型:
*/
String server,user,pass,mailfrom;
PropertyFileOperation op;
private JLabel jLabel;
private JList jList;
private JProgressBar jProgressBar;
private int sum,mailNum;
private Vector v=new Vector();
POPMail inst;
public void windowOpened(WindowEvent windowEvent) {
TMail doIt = new TMail();
doIt.start();
}
public class TMail extends Thread {
public void run(){
getMail();
}
}
public void windowClosed(WindowEvent windowEvent) { }
public void windowIconified(WindowEvent windowEvent) { }
public void windowDeiconified(WindowEvent windowEvent) { }
public void windowActivated(WindowEvent windowEvent) { }
public void windowDeactivated(WindowEvent windowEvent) { }
public void windowClosing(WindowEvent windowEvent) {
System.exit(0);
}
// private void center() {
// Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
// setLocation( ( ( screenDim.width - getSize().width ) / 2 ),
// ( ( screenDim.height - getSize().height ) / 2) );
// }
/**
* Auto-generated main method to display this JDialog
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
POPMail inst = new POPMail();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
//getMail();
}
public POPMail(int init)
{
inst = new POPMail();
inst.setLocationRelativeTo(null);
inst.setModal(true);
inst.setResizable(false);
inst.setVisible(true);
inst.pack();
//Thread.currentThread().sleep(2000);
}
public POPMail() {
super();
this.addWindowListener(this);
initGUI();
///getMail();
}
public void getMail()
{
///////////////
op=new PropertyFileOperation("MailServer.properties");//读取邮箱配置
v.addElement("加载邮箱配置");
this.jList.setListData(v);
////////////////重邮箱更新粮库服务器信息/////////////////////////////////////////////////////
int num=Integer.parseInt(op.getVal("num"));
server=op.getVal("server");
user=op.getVal("user");
pass=op.getVal("pass");
mailNum=num;
mailfrom=op.getVal("from");
//System.out.println(num);
v.addElement("加载服务器配置");
this.jList.setListData(v);
op=new PropertyFileOperation("GrainStoreServer.properties");
v.addElement("更新服务器信息");
this.jList.setListData(v);
receive(server, user, pass);
}
private void initGUI() {
try {
{
jProgressBar = new JProgressBar();
getContentPane().add(jProgressBar, BorderLayout.SOUTH);
this.jProgressBar.setMaximum(100);
this.jProgressBar.setMinimum(0);
}
{
jLabel = new JLabel();
getContentPane().add(jLabel, BorderLayout.NORTH);
jLabel.setText("\u670d\u52a1\u5668\u4fe1\u606f\u66f4\u65b0\u4e2d\uff0c\u8bf7\u7a0d\u540e...");
jLabel.setPreferredSize(new java.awt.Dimension(392, 36));
}
{
ListModel jListModel =
new DefaultComboBoxModel(
new String[] { "" });
jList = new JList();
getContentPane().add(jList, BorderLayout.CENTER);
jList.setModel(jListModel);
jList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jList.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
}
this.setSize(400, 263);
} catch (Exception e) {
//e.printStackTrace();
v.addElement("错误信息:"+e.getMessage());
this.jList.setListData(v);
}
}
/*public POPMail(String popserver,String popuser,String poppass,int num,String popfrom)
{
//SwingUtilities.invokeLater(new Runnable() {
//public void run() {
//POPMail inst = new POPMail();
//inst.setModal(true);
//inst.setVisible(true);
//}
//});
POPMail inst = new POPMail();
//inst.setModal(true);
inst.setVisible(true);
initGUI();
op=new PropertyFileOperation("GrainStoreServer.properties");
server=popserver;
user=popuser;
pass=poppass;
mailNum=num;
mailfrom=popfrom;
receive(popserver, popuser, poppass);
inst.pack();
}*/
/**
*<br>方法说明:接收邮件信息
*<br>输入参数:
*<br>返回类型:
*/
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);
//使用POP3会话机制,连接服务器
store = session.getStore("pop3");
store.connect(popServer, -1,popUser,popPassword);
//store.connect(popServer, popUser, popPassword);
//获取默认文件夹
folder = store.getDefaultFolder();
if (folder == null) throw new Exception("无默认文件夹");
//如果是收件箱
folder = folder.getFolder("INBOX");
if (folder == null) throw new Exception("无服务器信息");
//使用只读方式打开收件箱
folder.open(Folder.READ_ONLY);
//得到文件夹信息,获取邮件列表
Message[] msgs = folder.getMessages();
int mailCount=msgs.length;
int msgNum=0;
for (msgNum = 0; msgNum < mailCount; msgNum++){
//if(msgNum==mailNum)//如果检索的结果等于服务器的数目,跳出循环
// break;
int percent =(int)((msgNum+1)*100/mailCount);
//System.out.println(percent);
//this.jTextField.setText(Integer.toString(percent));
//this.jTextField.repaint();
//this.jTextField.validate();
this.jProgressBar.setValue(percent);
this.setTitle("服务器列表更新:"+Integer.toString(percent)+"%");
jProgressBar.repaint();
jProgressBar.validate();
//frame.setVisible(true);
//Thread.sleep(500);
saveMsg(msgs[msgNum]);
}
//Dimension screensize=Toolkit.getDefaultToolkit().getScreenSize();
//this.getParent().setLocation(0, 0);
//this.getParent().setSize(screensize.width,screensize.height-20);
}catch (Exception ex){
//ex.printStackTrace();
v.addElement("错误信息:"+ex.getMessage());
this.jList.setListData(v);
}
finally{
//释放资源
try{
if (folder!=null) folder.close(false);
if (store!=null) store.close();
}catch (Exception ex2) {
// ex2.printStackTrace();
v.addElement("错误信息:"+ex2.getMessage());
this.jList.setListData(v);
}
finally
{
this.dispose();
inst=null;
}
}
}
/**
*<br>方法说明:打印邮件信息
*<br>输入参数:Message message 信息对象
*<br>返回类型:
*/
public void saveMsg(Message message){
try{
//获得发送邮件地址
String from=((InternetAddress)message.getFrom()[0]).getPersonal();
if (from==null) from=((InternetAddress)message.getFrom()[0]).getAddress();
// System.out.println("FROM: "+from);
if(from.equals(mailfrom) || mailfrom.equals(""))
{
//获取主题
String subject=message.getSubject();
//System.out.println("SUBJECT: "+subject);
String[] str = subject.split("\\|");
if(str.length==3)
{
v.addElement("更新服务器"+str[0]+"配置");
this.jList.setListData(v);
op.setProperties("server"+str[0], str[1]);
op.setProperties("port"+str[0], str[2]);
// op.setProperties("flag"+str[0], "1");
// sum+=1;
// System.out.println("server"+str[0]+":"+str[1]);
// System.out.println("port"+str[0]+":"+str[2]);
// System.out.println(subject);
}
}
//获取信息对象
// Part messagePart=message;
//Object content=messagePart.getContent();
//附件
//if (content instanceof Multipart){
// messagePart=((Multipart)content).getBodyPart(0);
// System.out.println("[ Multipart Message ]");
// }
//获取content类型
//String contentType=messagePart.getContentType();
//如果邮件内容是纯文本或者是HTML,那么打印出信息
//System.out.println("CONTENT:"+contentType);
// 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){
//System.out.println(thisLine);
//thisLine=reader.readLine();
// }
//}
//System.out.println("-------------- END ---------------");
}catch (Exception ex){
//ex.printStackTrace();
v.addElement("错误信息:"+ex.getMessage());
this.jList.setListData(v);
}
}
}
package com.email;
import java.io.IOException;
import java.io.OutputStream;
import java.util.*;
import java.io.*;
import javax.swing.JOptionPane;
public class PropertyFileOperation {
private File file;
private String filename;
private Properties p = new Properties();
public PropertyFileOperation(String fileName)
{
file = new File (System.getProperty("user.dir")+"\\INF\\"+fileName);
filename=System.getProperty("user.dir")+"\\INF\\"+fileName;
getProperties();
}
public void getProperties(){
//ClassLoader cl = this.getClass().getClassLoader();
FileInputStream input;
// if(cl!=null)
//input=cl.getResourceAsStream(filename);
if(!file.exists())
{
//System.out.println(filename);
JOptionPane.showMessageDialog(null, "配置文件不存在","提示", JOptionPane.ERROR_MESSAGE);
return;
}
try
{
input = new FileInputStream(filename);
p.load(input);
}
catch(IOException e)
{
JOptionPane.showMessageDialog(null, "配置文件加载错误","提示", JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
}
//else
//input=ClassLoader.getSystemResourceAsStream(filename);
}
public void setProperties(String field,String val) {
p.setProperty(field,val);
try {
OutputStream fos = new FileOutputStream(file);
p.store(fos, filename);
fos.close();
} catch (FileNotFoundException ex) {
//System.out.println("file is NULL !!!");
ex.printStackTrace();
} catch (IOException ex) {
// System.out.println("IO is Error !!!");
ex.printStackTrace();
}
}
public String getVal(String field)
{
return p.getProperty(field);
}
}
附:配置文件
GrainStoreServer.properties
#C:\Documents and Settings\admin\workspace\JExplorer\INF\GrainStoreServer.properties
#Thu Sep 20 14:11:31 CST 2007
server04=cn.msn.com
server03=cn.yahoo.com.cn
port04=80
server02=www.sina.com
port03=80
server01=www.baidu.com
port02=80
port01=80
MailServer.properties
#C:\Documents and Settings\admin\workspace\JExplorer\INF\MailServer.properties
#Tue Sep 18 17:09:10 CST 2007
port=110
server=pop3.163.com
user=user@163.com
num=50
from=
pass=pass
Tree.properties
server1=[01]±±¾©
server2=[02]ÇàÔÆ
server3=[03]²ýƽ
server4=[04]Î÷³Ç
相关推荐
python学习资源
jfinal-undertow 用于开发、部署由 jfinal 开发的 web 项目
基于Andorid的音乐播放器项目设计(国外开源)实现源码,主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者,也可作为课程设计、期末大作业。
python学习资源
python学习资源
python学习一些项目和资源
【毕业设计】java-springboot+vue家具销售平台实现源码(完整前后端+mysql+说明文档+LunW).zip
HTML+CSS+JavaScarip开发的前端网页源代码
python学习资源
【毕业设计】java-springboot-vue健身房信息管理系统源码(完整前后端+mysql+说明文档+LunW).zip
成绩管理系统C/Go。大学生期末小作业,指针实现,C语言版本(ANSI C)和Go语言版本
1_基于大数据的智能菜品个性化推荐与点餐系统的设计与实现.docx
【毕业设计】java-springboot-vue交流互动平台实现源码(完整前后端+mysql+说明文档+LunW).zip
内容概要:本文主要探讨了在高并发情况下如何设计并优化火车票秒杀系统,确保系统的高性能与稳定性。通过对比分析三种库存管理模式(下单减库存、支付减库存、预扣库存),强调了预扣库存结合本地缓存及远程Redis统一库存的优势,同时介绍了如何利用Nginx的加权轮询策略、MQ消息队列异步处理等方式降低系统压力,保障交易完整性和数据一致性,防止超卖现象。 适用人群:具有一定互联网应用开发经验的研发人员和技术管理人员。 使用场景及目标:适用于电商、票务等行业需要处理大量瞬时并发请求的业务场景。其目标在于通过合理的架构规划,实现在高峰期保持平台的稳定运行,保证用户体验的同时最大化销售额。 其他说明:文中提及的技术细节如Epoll I/O多路复用模型以及分布式系统中的容错措施等内容,对于深入理解大规模并发系统的构建有着重要指导意义。
基于 OpenCV 和 PyTorch 的深度车牌识别
【毕业设计-java】springboot-vue教学资料管理系统实现源码(完整前后端+mysql+说明文档+LunW).zip
此数据集包含有关出租车行程的详细信息,包括乘客人数、行程距离、付款类型、车费金额和行程时长。它可用于各种数据分析和机器学习应用程序,例如票价预测和乘车模式分析。
把代码放到Word中,通过开发工具——Visual Basic——插入模块,粘贴在里在,把在硅基流动中申请的API放到VBA代码中。在Word中,选择一个问题,运行这个DeepSeekV3的宏就可以实现在线问答
【毕业设计】java-springboot+vue机动车号牌管理系统实现源码(完整前后端+mysql+说明文档+LunW).zip
【毕业设计】java-springboot-vue交通管理在线服务系统的开发源码(完整前后端+mysql+说明文档+LunW).zip