2016-02-02 4 views
0

Я написал код Java для отправки почты.Как установить цвет текста для моего текстового содержимого методов MIME message.setSubject()?

Мне нужно установить цвет темы электронной почты, т.е. мне нужно установить цвет текста метода message.setSubject().

Ниже приведены мои коды:

package comparexmlf1; 
import comparexmlf1.validatexml; 
import comparexmlf1.CarParser1; 
import comparexmlf1.OrderParser2; 
import java.io.BufferedReader; 
import java.io.FileInputStream; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.io.ObjectInputStream.GetField; 
import java.text.DateFormat; 
import java.text.SimpleDateFormat; 
import java.util.Calendar; 
import java.util.Enumeration; 
import java.util.Properties; 
import java.util.logging.Logger; 
import javax.lang.model.element.Element; 
import javax.mail.Message; 
import javax.mail.MessagingException; 
import javax.mail.Multipart; 
import javax.mail.Session; 
import javax.mail.Transport; 
import javax.mail.internet.AddressException; 
import javax.mail.internet.InternetAddress; 
import javax.mail.internet.MimeBodyPart; 
import javax.mail.internet.MimeMessage; 
import javax.mail.internet.MimeMultipart; 
import javax.swing.text.html.MinimalHTMLWriter; 
import javax.xml.soap.MimeHeader; 
import org.apache.log4j.Appender; 
import org.apache.log4j.FileAppender; 

public class mailer { 
static void sendmail() throws IOException, 
MessagingException,AddressException 
    { 
      String to1=CarParser1.to1; 
      DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy 
HH:mm:ss"); 
      Calendar cal = Calendar.getInstance(); 
      String to2 = CarParser1.to2; 
      String to3= CarParser1.to3; 
      String to4=CarParser1.to4; 
      String from = CarParser1.from; 
      String host = CarParser1.host; 
      Properties properties = System.getProperties(); 
      properties.setProperty("mail.smtp.host", host); 
      Session session = Session.getDefaultInstance(properties); 
      MimeMessage message = new MimeMessage(session); 
      int m_toterr,m_totwarn; 
      String getfilepath=""; 
      String filenamechange="D:/newlog 
/"+CarParser1.si_orderid+"_log.txt"; 
      System.out.println("New File Path for mail:"+filenamechange); 
      String pathLogFile = filenamechange; 
      Enumeration enumeration = 
CarParser1.logger.getRootLogger().getAllAppenders(); 
      try { 
       m_toterr=validatexml.Total_err; 
       message.setFrom(new InternetAddress(from)); 
       message.addRecipient(Message.RecipientType.TO, new 
InternetAddress(to1));     
       message.setSubject("<html><head></head><body><h1><p 
style=color:red> CAR Validation Report at : 
"+dateFormat.format(cal.getTime())+" for the Order ID : 
"+CarParser1.si_orderid+"</p></h1></body><html>","text/html" 
);     
        StringBuffer sb = new StringBuffer(); 
        FileInputStream fstream = new 
FileInputStream(pathLogFile); 
        BufferedReader br = new BufferedReader(new 
InputStreamReader(fstream)); 

        String singleLine; 
        while ((singleLine = br.readLine()) != null) 
        { 

         sb.append(singleLine + "<br>"); 

        } 
        br.close(); 
        String allLines = sb.toString(); 
        String allLines_html=" <html><head><title></title> 
</head>" 
          + "<body style=background- 
color:skyblue;>"+allLines+"</body ></html>"; 
        message.setContent(allLines_html, "text/html; 
charset=ISO-8859-1"); 
       Transport.send(message); 



       System.out.println("Email Sent successfully...."); 
       CarParser1.logger.info("Email Sent Successfully..."); 
       System.out.println(); 

      } 
      catch (MessagingException mex) 
      { 
       System.out.println("Invalid Email Address.please provide 
a valid email id to send with"); 
       mex.printStackTrace(); 


      } 



    } 
    } 

Может кто-нибудь помочь мне решить эту задачу.

Спасибо

ответ

1

Невозможно это сделать. Приложение, отображающее сообщение, выбирает способ отображения информации о субъекте, включая используемый шрифт и цвет. В отличие от тела сообщения, нет способа предоставить атрибуты «rich text» или html для Subject.

 Смежные вопросы

  • Нет связанных вопросов^_^