import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
public class Mail extends JFrame implements ActionListener{
private JButton b1;
private JPanel j1;
public Mail()
{
j1=new JPanel();
b1=new JButton("send");
j1.add(b1);
getContentPane().add(j1);
setSize(300,500);
setVisible(true);
b1.addActionListener(this);
}
public static void main(String d[])
{
new Mail();}
public void actionPerformed(ActionEvent e)
{
try{
Properties props=new Properties();
props.put("mail.smtp.host",true);
Session se=Session.getDefaultInstance(props,new Authenticator(){
public PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication("******","******");}
});
final Message msg=new MimeMessage(se);
Address to=new InternetAddress("*****");
Address from=new InternetAddress("******@163.com");
msg.setFrom(from);
msg.setRecipient(Message.RecipientType.TO,to);
msg.setSentDate(new Date());
msg.setSubject(("huang....."));
msg.setContent("hfdhffhs","GBK");
Runnable r=new Runnable(){
public void run(){
try{
Transport.send(msg);
System.out.println("send");}
catch(Exception eee){ System.out.println("send...err");}
}
};
Thread t=new Thread(r);
t.start();
}
catch(Exception ee){//ee.printStackTrace();
System.out.println("err");}
}
}
在书本上拷下来的..但是不知道什么原因用不了!(用户名和密码都没错!)