public class AlternateView extends AttachmentBase
Represents the format to view a message.
The following example shows how to create and add AlternateView to MailMessage.
[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 |
|---|
AlternateView(InputStream contentStream)
Initializes a new instance of the
AlternateView class. |
AlternateView(InputStream contentStream,
ContentType contentType)
Initializes a new instance of the
AlternateView class. |
AlternateView(InputStream contentStream,
String mediaType)
Initializes a new instance of the
AlternateView class. |
AlternateView(String fileName)
Initializes a new instance of the
AlternateView class. |
AlternateView(String fileName,
ContentType contentType)
Initializes a new instance of the
AlternateView class. |
AlternateView(String fileName,
String mediaType)
Initializes a new instance of the
AlternateView class. |
| Modifier and Type | Method and Description |
|---|---|
static AlternateView |
createAlternateViewFromString(String content)
Creates a AlternateView of using
the content specified in a string.
|
static AlternateView |
createAlternateViewFromString(String content,
Charset contentEncoding,
String mediaType)
Creates a AlternateView of using
the content specified in a string.
|
static AlternateView |
createAlternateViewFromString(String content,
ContentType contentType)
Creates a AlternateView of using
the content specified in a string.
|
static AlternateView |
createAlternateViewFromString(String content,
ContentType contentType,
int transferencoding)
Creates a AlternateView of using
the content specified in a string.
|
protected void |
dispose(boolean disposing)
Releases unmanaged and - optionally - managed resources.
|
URI |
getBaseUri()
Gets or sets the base URI.
|
LinkedResourceCollection |
getLinkedResources()
Gets the set of embedded resources referred to by this alternate view.
|
void |
setBaseUri(URI value)
Gets or sets the base URI.
|
close, dispose, generateContentId, getContentId, getContentStream, getContentType, getEncodingFromContent, getHeaders, getTransferEncoding, save, save, setContentId, setContentStream, setContentType, setTransferEncodingpublic AlternateView(String fileName)
Initializes a new instance of the AlternateView class.
fileName - Name of the file.public AlternateView(String fileName, String mediaType)
Initializes a new instance of the AlternateView class.
fileName - Name of the file.mediaType - Internet media type.public AlternateView(String fileName, ContentType contentType)
Initializes a new instance of the AlternateView class.
fileName - Name of the file.contentType - Content type.public AlternateView(InputStream contentStream)
Initializes a new instance of the AlternateView class.
contentStream - The content stream.public AlternateView(InputStream contentStream, String mediaType)
Initializes a new instance of the AlternateView class.
contentStream - The content stream.mediaType - Internet media type.public AlternateView(InputStream contentStream, ContentType contentType)
Initializes a new instance of the AlternateView class.
contentStream - The content stream.contentType - Content type.public final LinkedResourceCollection getLinkedResources()
Gets the set of embedded resources referred to by this alternate view.
Value: The linked resources.public final URI getBaseUri()
Gets or sets the base URI.
Value: The base URI.public final void setBaseUri(URI value)
Gets or sets the base URI.
Value: The base URI.public static AlternateView createAlternateViewFromString(String content)
Creates a AlternateView of using the content specified in a string.
content - The string that contains the content.public static AlternateView createAlternateViewFromString(String content, Charset contentEncoding, String mediaType)
Creates a AlternateView of using the content specified in a string.
content - The string that contains the content.contentEncoding - The content encoding.mediaType - Internet media type.public static AlternateView createAlternateViewFromString(String content, ContentType contentType)
Creates a AlternateView of using the content specified in a string.
content - The string that contains the content.contentType - Content type.public static AlternateView createAlternateViewFromString(String content, ContentType contentType, int transferencoding)
Creates a AlternateView of using the content specified in a string.
content - The string that contains the content.contentType - Content type.transferencoding - The transfer encoding.protected void dispose(boolean disposing)
Releases unmanaged and - optionally - managed resources.
dispose in class AttachmentBasedisposing - true to release
both managed and unmanaged resources; false to release only unmanaged resources.Copyright (c) 2008-2024 Aspose Pty Ltd. All Rights Reserved.