public class LinkedResource extends AttachmentBase
Represents an embedded resource in a message.
The following example shows how to embed objects using LinkedResource into an Email.
[Java]
MailMessage eml = new MailMessage(); eml.setFrom(MailAddress.to_MailAddress("AndrewIrwin@from.com")); eml.setTo(MailAddressCollection.to_MailAddressCollection("SusanMarc@to.com")); eml.setSubject("This is an email"); // Create the plain text part It is viewable by those clients that don't support HTML AlternateView plainView = AlternateView.createAlternateViewFromString("This is my plain text content", null, "text/plain"); // Create the HTML part.To embed images, we need to use the prefix 'cid' in the img src value. // The cid value will map to the Content-Id of a Linked resource. Thus <img src='cid:barcode'> // will map to a LinkedResource with a ContentId of 'barcode'. AlternateView htmlView = AlternateView.createAlternateViewFromString( "Here is an embedded image. <img src=cid:barcode>", null, "text/html"); // Create the LinkedResource (embedded image) and Add the LinkedResource to the appropriate view LinkedResource barcode = new LinkedResource("1.jpg", Image.JPEG); barcode.setContentId("barcode"); eml.getLinkedResources().addItem(barcode); eml.getAlternateViews().addItem(plainView); eml.getAlternateViews().addItem(htmlView); eml.save("EmbeddedImage_out.msg", SaveOptions.getDefaultMsgUnicode());
| Constructor and Description |
|---|
LinkedResource(InputStream contentStream)
Initializes a new instance of the
LinkedResource class. |
LinkedResource(InputStream contentStream,
ContentType contentType)
Initializes a new instance of the
LinkedResource class. |
LinkedResource(InputStream contentStream,
String mediaType)
Initializes a new instance of the
LinkedResource class. |
LinkedResource(String fileName)
Initializes a new instance of the
LinkedResource class. |
LinkedResource(String fileName,
ContentType contentType)
Initializes a new instance of the
LinkedResource class. |
LinkedResource(String fileName,
String mediaType)
Initializes a new instance of the
LinkedResource class. |
| Modifier and Type | Method and Description |
|---|---|
static LinkedResource |
createLinkedResourceFromString(String content)
Creates the linked resource from string.
|
static LinkedResource |
createLinkedResourceFromString(String content,
Charset contentEncoding,
String mediaType)
Creates the linked resource from string.
|
static LinkedResource |
createLinkedResourceFromString(String content,
ContentType contentType)
Creates the linked resource from string.
|
ContentDisposition |
getContentDisposition()
Gets Content-Disposition header
|
URI |
getContentLink()
Gets or sets a URI that the resource must match.
|
void |
setContentLink(URI value)
Gets or sets a URI that the resource must match.
|
close, dispose, dispose, generateContentId, getContentId, getContentStream, getContentType, getEncodingFromContent, getHeaders, getTransferEncoding, save, save, setContentId, setContentStream, setContentType, setTransferEncodingpublic LinkedResource(String fileName)
Initializes a new instance of the LinkedResource class.
fileName - The file name that holds the content for this resource.public LinkedResource(String fileName, String mediaType)
Initializes a new instance of the LinkedResource class.
fileName - The file name that holds the content for this resource.mediaType - Internet media type.public LinkedResource(String fileName, ContentType contentType)
Initializes a new instance of the LinkedResource class.
fileName - The file name that holds the content for this resource.contentType - The type of content.public LinkedResource(InputStream contentStream)
Initializes a new instance of the LinkedResource class.
contentStream - A stream that contains the content for this resource.public LinkedResource(InputStream contentStream, String mediaType)
Initializes a new instance of the LinkedResource class.
contentStream - A stream that contains the content for this resource.mediaType - Internet media type.public LinkedResource(InputStream contentStream, ContentType contentType)
Initializes a new instance of the LinkedResource class.
contentStream - A stream that contains the content for this resource.contentType - The type of content.public final URI getContentLink()
Gets or sets a URI that the resource must match.
public final void setContentLink(URI value)
Gets or sets a URI that the resource must match.
public final ContentDisposition getContentDisposition()
Gets Content-Disposition header
public static LinkedResource createLinkedResourceFromString(String content)
Creates the linked resource from string.
content - A string that contains the resource to be included in the email attachment.public static LinkedResource createLinkedResourceFromString(String content, Charset contentEncoding, String mediaType)
Creates the linked resource from string.
content - A string that contains the resource to be included in the email attachment.contentEncoding - The content encoding.mediaType - The MIME media type of the content.public static LinkedResource createLinkedResourceFromString(String content, ContentType contentType)
Creates the linked resource from string.
content - A string that contains the resource to be included in the email attachment.contentType - The type of the content.Copyright (c) 2008-2024 Aspose Pty Ltd. All Rights Reserved.