Some questions related to implementation of image inside email signature?

前端 未结 2 398
温柔的废话
温柔的废话 2021-01-03 17:25

i need to implement the email signature with image.As of now we only support the text in email signature which is already working.i need to provide the functionality where

相关标签:
2条回答
  • 2021-01-03 17:56

    To include images in the email message, first you have to include the images as MIME attachments in the email. Each of these attachments must have a "Content-ID" header.

    --f46d0444ea0d6991ba04b91c92e6
    Content-Type: image/gif; name="theImage.gif"
    Content-Transfer-Encoding: base64
    Content-ID: <theImage@abcd>
    
    [base64 string]
    --f46d0444ea0d6991ba04b91c92e6--
    

    2) Then, in the email message, include the Content-ID in the src attribute of the <img> tag.

    <img src="cid:theImage@abcd" />
    
    0 讨论(0)
  • 2021-01-03 18:13

    For Gmail to see the embedded image from byte array, I posted an answer on another similar question which is to use ByteArrayDataSource and embed it to the HtmlEmail. Here's the code snippet:

    import javax.mail.util.ByteArrayDataSource;
    import org.apache.commons.mail.ImageHtmlEmail;
    ...
    ImageHtmlEmail email = new ImageHtmlEmail();
    byte[] qrImageBytes = createQRCode(); // get your image byte array
    ByteArrayDataSource qrImageDataSource = new ByteArrayDataSource(qrImageBytes, "image/png");
    String contentId = email.embed(qrImageDataSource, "QR Image");
    
    0 讨论(0)
提交回复
热议问题