2012-04-24 1 views
0

:수 없습니다 나는이 같은 자바를 사용하여 이메일을 보내고

StringBuilder stringBuilder=new StringBuilder("<p>Priority:"+escalationDTO.getEscalationPriority()+"</p><br/><p>Status="+escalationDTO.getEscalationStatus()+"</p><br/><p>Type="+escalationDTO.getEscalationType()+"</p><br/><p>Description="+escalationDTO.getEscalationDescription()+"</p><br/><p>StartDate="+new Date(new java.util.Date().getTime())+"</p><br/><p>EndDate="+sqldate1+"</p>" ); 

그러나 다음과 같이 내 사서함에 도착 출력은 다음과 같습니다

<p>Priority:P1</p><br/><p>Status=closed</p><br/><p>Type=C</p><br/><p>Description=werrwe</p><br/><p>StartDate=2012-04-24</p><br/><p>EndDate=2010-08-09</p> 

난 몰라 전자 메일에 HTML 태그가 나타나기를 원합니다. 각 <p> 요소는 줄 바꿈을 유발해야합니다.

package helper; 

/** 
* Created by IntelliJ IDEA. 
* User: Milind 
* Date: 4/24/12 
* Time: 4:05 PM 
* To change this template use File | Settings | File Templates. 
*/ 

import java.util.Properties; 

import javax.mail.Message; 
import javax.mail.MessagingException; 
import javax.mail.Session; 
import javax.mail.Transport; 
import javax.mail.Message.RecipientType; 
import javax.mail.internet.AddressException; 
import javax.mail.internet.InternetAddress; 
import javax.mail.internet.MimeMessage; 

public class SendMail { 

    private String from; 
    private String to; 
    private String subject; 
    private String text; 

    public SendMail(String subject1,String body) { 
     from = "[email protected]"; 
     to = "[email protected]"; 
     subject = subject1; 
     text = body; 
     System.out.println(subject); 
    } 

    public void send(){ 

     Properties props = new Properties(); 
     props.put("mail.smtp.host", "smtp.bb.zedo.com"); 
     props.put("mail.smtp.port", "25"); 

     Session mailSession = Session.getDefaultInstance(props); 
     Message simpleMessage = new MimeMessage(mailSession); 

     InternetAddress fromAddress = null; 
     InternetAddress toAddress = null; 
     try { 
      fromAddress = new InternetAddress(from); 
      toAddress = new InternetAddress(to); 
     } catch (AddressException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

     try { 
      simpleMessage.setFrom(fromAddress); 
      simpleMessage.setRecipient(RecipientType.TO, toAddress); 
      simpleMessage.setSubject(subject); 
      simpleMessage.setText(text); 
      Transport.send(simpleMessage); 

     } catch (MessagingException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 
} 

답변

2
Message.setContent(stringBuilder , "text/html"); 
3

당신이 당신의 MIME 메시지에 "text/html과"에 대한 내용을 설정해야합니다 :

이 내 메일 클래스입니다.

MimeMessage message = new MimeMessage(mailSession); 
message.setContent("<h1>Hello world</h1>", "text/html"); 
관련 문제