Pessoal,
 
Estou com problemas pra setar o tipo de MIME para "text/html" com o JavaMail. Elaboro o texto em HTML mas o mime continua setado para "text/plain", pois o mesmo não interpreta as tags HTML. Abaixo o código que eu estou utilizando:
 
Obrigado,
 
 
 
   import java.util.*;
   import java.io.*;
   import javax.mail.*;
   import javax.mail.internet.*;
   import javax.activation.*;
   public class SendMail {
      public static int Send(String SMTPServer,
                             String Sender,
                             String Recipient,
                             String CcRecipient,
                             String BccRecipient,
                             String Subject,
           String SMultipart,                               
                             String Body,
                             String ErrorMessage[],
                             String Attachments) {
 
         int ErrorStatus = 0;
 
     Properties props = System.getProperties();
     props.put("mail.smtp.host", SMTPServer);
          Session session = Session.getDefaultInstance(props, null);
 
          try {
             MimeMessage msg = new MimeMessage(session);
 
             {
                InternetAddress[] TheAddresses =
                                         InternetAddress.parse(Sender);
                msg.addFrom(TheAddresses);
             }
 
             {
                InternetAddress[] TheAddresses =
                                      InternetAddress.parse(Recipient);
                msg.addRecipients(Message.RecipientType.TO,
                                  TheAddresses);
             }
 
             if (null != CcRecipient) {
                InternetAddress[] TheAddresses =
                                    InternetAddress.parse(CcRecipient);
                msg.addRecipients(Message.RecipientType.CC,
                                  TheAddresses);
             }
 
             if (null != BccRecipient) {
                InternetAddress[] TheAddresses =
                                   InternetAddress.parse(BccRecipient);
                msg.addRecipients(Message.RecipientType.BCC,
                                  TheAddresses);
             }
 
             msg.setSubject(Subject);
 
             Multipart mp = new MimeMultipart();
             
             // aqui está o que eu estou tentando fazer: mudar o MIME para text/html ao inves de text/plain             
             if (SMultipart != null){
              msg.setContent(Body,"text/html");
             }
            
 
             {
                MimeBodyPart mbp = new MimeBodyPart();
                mbp.setText(Body);
 
                mp.addBodyPart(mbp);
             }
 
             if (null != Attachments) {
                int StartIndex = 0, PosIndex = 0;
                while (-1 != (PosIndex = Attachments.indexOf("///",
                                                       StartIndex))) {
                   MimeBodyPart mbp = new MimeBodyPart();
                   FileDataSource fds =
                   new FileDataSource(Attachments.substring(StartIndex,
                                                            PosIndex));
                   mbp.setDataHandler(new DataHandler(fds));
                   mbp.setFileName(fds.getName());
                   mp.addBodyPart(mbp);
                   PosIndex += 3;
                   StartIndex = PosIndex;
                }
                if (StartIndex < Attachments.length()) {
                   MimeBodyPart mbp = new MimeBodyPart();
                   FileDataSource fds =
                 new FileDataSource(Attachments.substring(StartIndex));
                   mbp.setDataHandler(new DataHandler(fds));
                   mbp.setFileName(fds.getName());
                   mp.addBodyPart(mbp);
                }
             }
 
             msg.setContent(mp);
 
             msg.setSentDate(new Date());
 
             Transport.send(msg);
          } catch (MessagingException MsgException) {
               ErrorMessage[0] = MsgException.toString();
               Exception TheException = null;
               if ((TheException = MsgException.getNextException()) !=
                                                                  null)
                  ErrorMessage[0] = ErrorMessage[0] + "\n" +
                                    TheException.toString();
              ErrorStatus = 1;
          }
          return ErrorStatus;
      }
   }
 
 
 
 
 

Responder a