public boolean mainto()
創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站制作、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的陳巴爾虎網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
{
boolean flag = true;
//建立郵件會(huì)話
Properties pro = new Properties();
pro.put("mail.smtp.host","smtp.qq.com");//存儲(chǔ)發(fā)送郵件的服務(wù)器
pro.put("mail.smtp.auth","true"); //通過(guò)服務(wù)器驗(yàn)證
Session s =Session.getInstance(pro); //根據(jù)屬性新建一個(gè)郵件會(huì)話
//s.setDebug(true);
//由郵件會(huì)話新建一個(gè)消息對(duì)象
MimeMessage message = new MimeMessage(s);
//設(shè)置郵件
InternetAddress fromAddr = null;
InternetAddress toAddr = null;
try
{
fromAddr = new InternetAddress(451144426+"@qq.com"); //郵件發(fā)送地址
message.setFrom(fromAddr); //設(shè)置發(fā)送地址
toAddr = new InternetAddress("12345367@qq.com"); //郵件接收地址
message.setRecipient(Message.RecipientType.TO, toAddr); //設(shè)置接收地址
message.setSubject(title); //設(shè)置郵件標(biāo)題
message.setText(content); //設(shè)置郵件正文
message.setSentDate(new Date()); //設(shè)置郵件日期
message.saveChanges(); //保存郵件更改信息
Transport transport = s.getTransport("smtp");
transport.connect("smtp.qq.com", "451144426", "密碼"); //服務(wù)器地址,郵箱賬號(hào),郵箱密碼
transport.sendMessage(message, message.getAllRecipients()); //發(fā)送郵件
transport.close();//關(guān)閉
}
catch (Exception e)
{
e.printStackTrace();
flag = false;//發(fā)送失敗
}
return flag;
}
這是一個(gè)javaMail的郵件發(fā)送代碼,需要一個(gè)mail.jar
算是最簡(jiǎn)單的吧
package cn.job01;
import java.util.Scanner;
public class Lx07 {
public static void choice() {
System.out.println("登陸菜單 ");
System.out.println("1登陸系統(tǒng)");
System.out.println("2退出");
}
static void choice1() {
System.out.println("購(gòu)物管理系統(tǒng)客戶信息");
System.out.println("1顯示所有客戶信息");
System.out.println("2添加客戶信息");
System.out.println("3修改客戶信息");
System.out.println("4查詢客戶信息");
}
static void choice2() {
System.out.println("購(gòu)物管理系統(tǒng)真情回饋");
System.out.println("1幸運(yùn)大放送");
System.out.println("2幸運(yùn)抽獎(jiǎng)");
System.out.println("3生日問(wèn)候");
}
public static void main(String[] args) {
choice();
Scanner input = new Scanner(System.in);
System.out.println("請(qǐng)輸入1or2");
int num = input.nextInt();
switch (num) {
case 1:
System.out.println("主菜單");
System.out.println("1客戶信息管理");
System.out.println("2購(gòu)物結(jié)算");
System.out.println("3真情回饋");
System.out.println("4注銷");
break;
}
System.out.println("選擇輸入數(shù)字");
int num1 = input.nextInt();
switch (num1) {
case 1:
choice1();
break;
case 2:
System.out.println("購(gòu)物結(jié)算");
break;
case 3:
choice2();
break;
case 4:
choice();
break;
}
}
}
import java.util.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.io.*;
class 商品 extends Panel
{String 代號(hào),名稱;int 庫(kù)存;float 單價(jià);
商品(String 代號(hào),String 名稱,int 庫(kù)存,float 單價(jià))
{this.代號(hào)=代號(hào);this.名稱=名稱;this.庫(kù)存=庫(kù)存;this.單價(jià)=單價(jià);
}
}
class ShowWin extends JFrame implements ActionListener
{ Hashtable hashtable=null;
JTextField 代號(hào)文本框=new JTextField(),
名稱文本框=new JTextField(),
庫(kù)存文本框=new JTextField(),
單價(jià)文本框=new JTextField(),
查詢文本框=new JTextField(),
查詢信息文本框=new JTextField(),
刪除文本框=new JTextField();
JButton b_add=new JButton("添加商品"),
b_del=new JButton("刪除商品"),
b_xun=new JButton("查詢商品"),
b_xiu=new JButton("修改商品"),
b_show=new JButton("顯示商品清單");
JTextArea 顯示區(qū)=new JTextArea(25,10);
ShowWin()
{super("倉(cāng)庫(kù)管理窗口");
hashtable=new Hashtable();
Container con=getContentPane();
JScrollPane pane=new JScrollPane(顯示區(qū));
顯示區(qū).setEditable(false);
JPanel save=new JPanel();
save.setLayout(new GridLayout(8,2));
save.add(new Label("輸入代號(hào):"));
save.add(代號(hào)文本框);
save.add(new Label("輸入名稱:"));
save.add(名稱文本框);
save.add(new Label("輸入庫(kù)存:"));
save.add(庫(kù)存文本框);
save.add(new Label("輸入單價(jià):"));
save.add(單價(jià)文本框);
save.add(new Label("單擊添加:"));
save.add(b_add);
save.add(new Label("單擊修改:"));
save.add(b_xiu);
save.add(new Label("輸入查詢代號(hào):"));
save.add(查詢文本框);
save.add(new Label("單擊查詢:"));
save.add(b_xun);
JPanel del=new JPanel();
del.setLayout(new GridLayout(2,2));
del.add(new Label("輸入刪除的代號(hào):"));
del.add(刪除文本框);
del.add(new Label("單擊刪除:"));
del.add(b_del);
JPanel show=new JPanel();
show.setLayout(new BorderLayout());
show.add(pane,BorderLayout.CENTER);
show.add(b_show,BorderLayout.SOUTH);
JSplitPane split_one,split_two;
split_one=new JSplitPane(JSplitPane.VERTICAL_SPLIT,save,del);
split_two=new
JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,split_one,show);
con.add(split_two,BorderLayout.CENTER);
JPanel xun=new JPanel();
xun.add(new Label("所得信息:"));
xun.add(查詢信息文本框);
xun.setLayout(new GridLayout(2,1));
con.add(xun,BorderLayout.SOUTH);
b_add.addActionListener(this);
b_del.addActionListener(this);
b_xun.addActionListener(this);
b_xiu.addActionListener(this);
b_show.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==b_add)
{String daihao=null,mingcheng=null;int kucun=0;float danjia=0.0f;
daihao=代號(hào)文本框.getText();mingcheng=名稱文本框.getText();
kucun=Integer.parseInt(庫(kù)存文本框.getText());
danjia=Float.valueOf(單價(jià)文本框.getText()).floatValue();
商品 goods=new 商品(daihao,mingcheng,kucun,danjia);
hashtable.put(daihao,goods);
try{FileOutputStream file=new FileOutputStream("goods.txt");
ObjectOutputStream out=new ObjectOutputStream(file);
out.writeObject(hashtable); out.close();
}
catch(IOException event){}
}
else if(e.getSource()==b_del)
{String daihao1=刪除文本框.getText();
try{FileInputStream come_in=new FileInputStream("goods.txt");
ObjectInputStream in=new ObjectInputStream(come_in);
hashtable=(Hashtable)in.readObject(); //////
in.close();
}
catch(ClassNotFoundException event){}
catch(IOException event){}
商品 temp=(商品)hashtable.get(daihao1);
{hashtable.remove(daihao1);}
try{FileOutputStream file=new FileOutputStream("goods.txt");
ObjectOutputStream out =new ObjectOutputStream(file);
out.writeObject(hashtable);//
out.close();
}
catch(IOException event){}
}
//
else if(e.getSource()==b_xun)
{ String aa;
aa=查詢文本框.getText();
查詢信息文本框.setText(null);
try{FileInputStream come_in=new FileInputStream("goods.txt");
ObjectInputStream in =new ObjectInputStream(come_in);
hashtable=(Hashtable)in.readObject(); ////
in.close();
}
catch(ClassNotFoundException event){}
catch(IOException event){}
商品 a=(商品)hashtable.get(aa);
查詢信息文本框.setText(" 代號(hào):"+a.代號(hào)+" 名稱:"+a.名稱+" 庫(kù)存:"+a.庫(kù)存+" 單價(jià):"+a.單價(jià));
}
//
else if(e.getSource()==b_xiu)
{ String bb;
bb=代號(hào)文本框.getText();
try{FileInputStream come_in=new FileInputStream("goods.txt");
ObjectInputStream in=new ObjectInputStream(come_in);
hashtable=(Hashtable)in.readObject(); //////
in.close();
}
catch(ClassNotFoundException event){}
catch(IOException event){}
商品 temp=(商品)hashtable.get(bb);
{hashtable.remove(bb);}
try{FileOutputStream file=new FileOutputStream("goods.txt");
ObjectOutputStream out =new ObjectOutputStream(file);
out.writeObject(hashtable);//
out.close();
}
catch(IOException event){}
String daihao1=null,mingcheng1=null;int kucun1=0;float danjia1=0.0f;
daihao1=代號(hào)文本框.getText();mingcheng1=名稱文本框.getText();
kucun1=Integer.parseInt(庫(kù)存文本框.getText());
danjia1=Float.valueOf(單價(jià)文本框.getText()).floatValue();
商品 goods1=new 商品(daihao1,mingcheng1,kucun1,danjia1);
hashtable.put(daihao1,goods1);
try{FileOutputStream file=new FileOutputStream("goods.txt");
ObjectOutputStream out=new ObjectOutputStream(file);
out.writeObject(hashtable); out.close();
}
catch(IOException event){}
}
//
else if(e.getSource()==b_show)
{ 顯示區(qū).setText(null);
try{FileInputStream come_in=new FileInputStream("goods.txt");
ObjectInputStream in =new ObjectInputStream(come_in);
hashtable=(Hashtable)in.readObject(); ////
}
catch(ClassNotFoundException event){}
catch(IOException event){}
Enumeration enum=hashtable.elements();
while(enum.hasMoreElements())
{ 商品 te=(商品)enum.nextElement();
顯示區(qū).append("商品代號(hào):"+te.代號(hào)+" ");
顯示區(qū).append("商品名稱:"+te.名稱+" ");
顯示區(qū).append("商品庫(kù)存:"+te.庫(kù)存+" ");
顯示區(qū).append("商品單價(jià):"+te.單價(jià)+" ");
顯示區(qū).append("\n ");
}
}
}
}
public class LinkListFour
{public static void main(String args[])
{ ShowWin win=new ShowWin();
win.setSize(400,350);
win.setVisible(true);
win.addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{ System.exit(0);}});
}
}