日期:2014-05-20 浏览次数:20653 次
public static void main(String[] args) throws Exception { Properties props = new Properties(); props.setProperty("mail.debug", "true"); //输出debug信息 props.setProperty("mail.transport.protocol","smtp"); //协议 props.setProperty("mail.auth", "true"); //用户验证 Session session =Session.getInstance(props); // 创建Session String date = DateFormat.getTimeInstance().format(new Date(System.currentTimeMillis())); //区分标示作用 Message message = new MimeMessage(session); // 创建邮件体 message.setText("路遥知马力!"); //邮件内容:简单的 message.setSubject("javaMial" + date ); //邮件主题 message.setFrom(new InternetAddress("862123204@qq.com")); //发件人(这里好像要和connect()里面的user要相同???) Transport transport = session.getTransport(); //创建发送器 transport.connect("smtp.qq.com", 25, "862123204", "password"); //连接smtp服务器,准备发送 transport.sendMessage(message, new Address[]{new InternetAddress("studyjavaee@163.com"),new InternetAddress("zhanglelife@163.com")}); transport.close(); //关闭资源