如何使用org.apache.velocity.velocitycontext发送映像


MimeMessagePreparator mimeMessagePreparator=new MimeMessagePreparator() {
@Override
public void prepare(MimeMessage mimeMessage) throws Exception {
MimeMessageHelper mimeMessageHelper=new MimeMessageHelper(mimeMessage);
                    mimeMessageHelper.setTo(requestQuotationPojo.getEmailId().toString());
                    mimeMessageHelper.setFrom("vikasglobaljapan@gmail.com");
                    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

<!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>
  • 我想您的图像是字节数组。因此,您应该将图像添加到速度上下文中,例如base64字符串。

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

  • 并在模板文件中使用此IMG标签。

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

$ {webSiteName}:写下您的网站名称。

$ {rfqdetails.image}:您的图像路径。

喜欢您的图像URL:http://test.com/folder/abc.png

#set($imgsrc="http://${websitename}/${rfqDetails.image})
 <img width="50" src="$imgsrc" border="0" height="50" alt="test">

相关内容

  • 没有找到相关文章

最新更新