sky

道,可道,名,可名。

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  1 Posts :: 0 Stories :: 0 Comments :: 0 Trackbacks
public class SendMail {
public static void main(String[] args) {
        try {
            Properties p = new Properties(); //Properties p = System.getProperties();  
            p.put("mail.smtp.auth", "true");  
            p.put("mail.transport.protocol", "smtp");  
            p.put("mail.smtp.host", "smtp.163.com");  
            p.put("mail.smtp.port", "25");  
            //建立会话  
            Session session = Session.getInstance(p);  
            Message msg = new MimeMessage(session); //建立信息  
   
            msg.setFrom(new InternetAddress("skiyra@163.com")); //发件人  
            msg.setRecipient(Message.RecipientType.TO, new InternetAddress("myb4562@163.com")); //收件人  
   
            msg.setSentDate(new Date()); // 发送日期  
            msg.setSubject("答话稀有"); // 主题  
            msg.setText("快点下在"); //内容  
            // 邮件服务器进行验证  
            Transport tran = session.getTransport("smtp");  
            tran.connect("smtp.163.com", "skiyra", "aaaaaaaaaaaa");  
            // bluebit_cn是用户名,xiaohao是密码  
            tran.sendMessage(msg, msg.getAllRecipients()); // 发送  
            System.out.println("邮件发送成功");  
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
} //发件人  
 
}
}
posted on 2012-05-15 20:44 skiyra 阅读(98) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: