当前位置: 代码迷 >> Java相关 >> 关于发mail的问题!
  详细解决方案

关于发mail的问题!

热度:562   发布时间:2007-05-28 20:18:34.0
关于发mail的问题!

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");}
}
}



在书本上拷下来的..但是不知道什么原因用不了!(用户名和密码都没错!)

搜索更多相关的解决方案: mail  

----------------解决方案--------------------------------------------------------
163邮箱我也没发成功过~~~~~~
可能是我弄错了什么地方,不过126、GMAIL等都是可以的

----------------解决方案--------------------------------------------------------
  相关解决方案