2016-11-25 47 views
0
MimeMessagePreparator mimeMessagePreparator=new MimeMessagePreparator() { 

@Override 
public void prepare(MimeMessage mimeMessage) throws Exception { 

MimeMessageHelper mimeMessageHelper=new MimeMessageHelper(mimeMessage); 
        mimeMessageHelper.setTo(requestQuotationPojo.getEmailId().toString()); 
        mimeMessageHelper.setFrom("[email protected]"); 
        mimeMessageHelper.setText("Your Request Quotation Number"+requestQuotationPojo.getRfqId()); 
        mimeMessageHelper.setSubject("Request Quotation Details"); 
    VelocityContext velocityContext = new VelocityContext(); 

    requestQuotationPojo.setImage(new StringBuffer(application_url.concat(requestQuotationPojo.getImage().toString()))); 
    requestQuotationPojo.setRfqId(new StringBuffer(rfqId)); 

    velocityContext.put("image", requestQuotationPojo.getImage()); 
    velocityContext.put("rfqDetails", requestQuotationPojo); 
        velocityContext.put("image",application_url.concat(requestQuotationPojo.getImage().toString())); 

    StringWriter stringWriter = new StringWriter(); 
    velocityEngine.mergeTemplate("com/gjcp/dao/daoImpl/customer/templateName.vm", "UTF-8", velocityContext, stringWriter); 
        mimeMessageHelper.setText(stringWriter.toString(), true); 
       } 

template.vm如何發送使用org.apache.velocity.VelocityContext圖像的電子郵件

<!doctype html> 
<html lang="en"> 
<head> 
<style> 
table, th, td { 
    border: 1px solid black; 
} 
</style> 
    <meta charset="UTF-8"> 
    <meta name="Generator" content="EditPlus®"> 
    <meta name="Author" content=""> 
    <meta name="Keywords" content=""> 
    <meta name="Description" content=""> 
    <title>Document</title> 
</head> 
<body> 
<table style="width:100%"> 
  <tr> 
    <th>Product Name</th> 
    <th>Quote Number</th> 
    <th>Image</th> 
    <th>Quantity</th> 
  </tr> 
    <tr> 
    <td>${rfqDetails.productName}</td> 
    <td> ${rfqDetails.rfqId}</td> 
    <td><img src="${rfqDetails.image}" border="0" width="50" height="50"></td> 
    <td>${rfqDetails.quantity}</td> 
    </tr> 

</table> 


</body> 
</html> 

回答

1
  • 我想,你的形象是一個字節數組。所以你應該將圖像添加到速度上下文中作爲base64字符串。

    velocityContext.put("image", Base64.encode(requestQuotationPojo.getImage()));

  • 並使用你的模板文件,這個img標籤。

    <img src="data:image/jpg;base64,${image}" border="0" width="50" height="50"/>

+0

在我的數據庫存儲圖像路徑URL。同時發送電子郵件img src

+0

我從數據庫中獲取圖像URL。同時向我的圖像路徑中包含的Gmail郵件路徑發送電子郵件,如

1

$ {} websitename:寫你的網站名稱。

$ {rfqDetails.image}:您的圖片路徑。

像圖片網址:http://test.com/folder/abc.png

#set($imgsrc="http://${websitename}/${rfqDetails.image}) 

<img width="50" src="$imgsrc" border="0" height="50" alt="test"> 
相關問題