简单的Java邮件发送实例

Properties props = new Properties();

       props.setProperty("mail.smtp.auth", "true");

       props.setProperty("mail.transport.protocol", "smtp");

       props.setProperty("mail.host", "smtp.163.com");

      

       Session session = Session.getInstance(props, new Authenticator(){

 

           @Override

           protected PasswordAuthentication getPasswordAuthentication() {

              // TODO Auto-generated method stub

              return new PasswordAuthentication("lili","******");

           }

          

       });

       session.setDebug(true);

      

       Message msg = new MimeMessage(session);

       msg.setFrom(new InternetAddress("[email protected]"));

       msg.setRecipients(RecipientType.TO, InternetAddress.parse("[email protected],[email protected]"));

       msg.setContent("<span style='color:red;'>哥哥呵呵</span>", "text/html;charset=gbk");

       msg.setSubject("lili主题");

      

       Transport.send(msg);

你可能感兴趣的:(java,html,qq)