Add Embedded Images to Email Message in Aspose.Email
Contents
[
Hide
]
Aspose.Email - Add Embedded Images to Email Message
With Aspose.Email Java developers can easily embed any image into an email message as well as attach it, as discussed in Manage Attachments in Email Message. To embed an image, Aspose.Email uses a specialized class, LinkedResource.
Java
// Set Html body. It also contains <img> tag with cid. cid = LinkedResource.ContentID
message.setHtmlBody("<b>This line is in bold.</b> <br/> <br/>"
+ "<font color=blue>This line is in blue color</font><br><br>" +
"Here is an embedded image.<img src=cid:companylogo>");
// Add linked resource
LinkedResource res = new LinkedResource(dataDir + "Aspose.png", MediaTypeNames.Image.PNG);
res.setContentId("companylogo");
// Add Linked resource to the message's Linked resource collection
message.getLinkedResources().addItem(res);
Download Running Code
Download Sample Code
For more details, visit Add Embedded Images to Email Message.