忘了说: 那个o是message[i].getContent()对象

解决方案 »

  1.   

    看看这个有没有帮助
    <- 
    ...... 
    // Adding a subject to the mail 
    msg.setSubject(subject); 
    // Adding the X-mailer to the mail (the name of the Mailer) 
    msg.setHeader("X-Mailer", mailer); //TEXT 
    MimeBodyPart multitext = new MimeBodyPart(); // This will add the text to the mime body part 
    texto += "Text plain here"; 
    multitext.setText(texto); // setting the right values for the Header 
    multitext.setHeader("Content-Type", "text/plain; 
    charset=\"iso-8859-1\""); 
    multitext.setHeader("Content-Transfer-Encoding", "8bit"); 
    // This will return all the fields to be signed 
    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    multitext.writeTo(baos); 
    System.out.println("->>>>" + baos.toString()+"\n <------"); // HTml 
    MimeBodyPart multipartHTML = new MimeBodyPart(); 
    // 
    multipartHTML.setText("<html>" + text + "</html>"); 
    // setting the right values for the Header 
    multipartHTML.setHeader("Content-Type","text/html;"); 
    multipartHTML.setHeader("Content-Transfer- Encoding", "base64"); 
    multipartHTML.setHeader("charset","\"gb2312\""); //Creating a multipart that will englobe all the already defined bodyparts, this will also define the header of the message Multipart multipart = new MimeMultipart("alternative"); 
    // Adding both, the text, and the signature 
    multipart.addBodyPart(multitext); 
    multipart.addBodyPart(multipartHTML); 
    // Adding the date to the mail 
    msg.setSentDate(new Date()); 
    // Adding the mime multi part to the mail 
    msg.setContent(multipart); // send the thing off System.out.println("\nMessage ready sending Mail."); Transport.send(msg); System.out.println("\nMail was sent successfully."); 
    ->