Attachment
Inheritance: java.lang.Object, com.aspose.email.AttachmentBase
All Implemented Interfaces: com.aspose.email.IPreferredTextEncodingProvider, com.aspose.email.IAttachment
public class Attachment extends AttachmentBase implements IPreferredTextEncodingProvider, IAttachment
Represents an e-mail attachment.
The following example shows how to add and remove an Attachment from MailMessage.
[Java]
// Create an instance of MailMessage class MailMessage eml = new MailMessage(); eml.setFrom(MailAddress.to_MailAddress("sender@sender.com")); eml.setTo(MailAddressCollection.to_MailAddressCollection("receiver@gmail.com")); // Load an attachment Attachment attachment = new Attachment("1.txt"); eml.getAttachments().addItem(attachment); // Remove attachment from your MailMessage eml.getAttachments().removeItem(attachment);
Constructors
Constructor | Description |
---|---|
Attachment(String fileName) | Initializes a new instance of the Attachment class. |
Attachment(String fileName, String mediaType) | Initializes a new instance of the Attachment class. |
Attachment(String fileName, ContentType contentType) | Initializes a new instance of the Attachment class. |
Attachment(InputStream contentStream, String name) | Initializes a new instance of the Attachment class. |
Attachment(InputStream contentStream, String name, String mediaType) | Initializes a new instance of the Attachment class. |
Attachment(InputStream contentStream, ContentType contentType) | Initializes a new instance of the Attachment class. |
Methods
Method | Description |
---|---|
close() | |
createAttachmentFromString(String content, ContentType contentType) | Creates the attachment from string. |
createAttachmentFromString(String content, String name) | Creates the attachment from string. |
createAttachmentFromString(String content, String name, Charset contentEncoding, String mediaType) | Creates the attachment from string. |
dispose() | Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. |
equals(Object arg0) | |
getClass() | |
getContentDisposition() | Gets Content-Disposition header |
getContentId() | Gets or sets the content id. |
getContentStream() | Gets or sets the content stream. |
getContentType() | Gets or sets the type of the content. |
getHeaders() | Gets headers collection of attachment. |
getName() | Gets or sets an attachment name |
getNameEncoding() | Gets or sets an encoding of attachment name |
getPreferredTextEncoding() | Gets or sets a preferred text encoding |
getTransferEncoding() | Gets or sets the transfer encoding. |
hashCode() | |
isEmbeddedMessage() | Gets a value indicating whether the attachment is an embedded message. |
isTnef() | Gets a value indicating whether the attachment is TNEF formatted message. |
isUri() | Gets a value indicating whether attachment is URI-attachment. |
notify() | |
notifyAll() | |
save(OutputStream stream) | Saves the specified stream. |
save(String fileName) | Saves the specified file name. |
setContentId(String value) | Gets or sets the content id. |
setContentStream(InputStream value) | Gets or sets the content stream. |
setContentType(ContentType value) | Gets or sets the type of the content. |
setName(String value) | Gets or sets an attachment name |
setNameEncoding(Charset value) | Gets or sets an encoding of attachment name |
setPreferredTextEncoding(Charset value) | Gets or sets a preferred text encoding |
setTransferEncoding(int value) | Gets or sets the transfer encoding. |
toString() | |
wait() | |
wait(long arg0) | |
wait(long arg0, int arg1) |
Attachment(String fileName)
public Attachment(String fileName)
Initializes a new instance of the Attachment class.
Parameters:
Parameter | Type | Description |
---|---|---|
fileName | java.lang.String | Name of the file. |
Attachment(String fileName, String mediaType)
public Attachment(String fileName, String mediaType)
Initializes a new instance of the Attachment class.
Parameters:
Parameter | Type | Description |
---|---|---|
fileName | java.lang.String | Name of the file. |
mediaType | java.lang.String | Type media type name. |
Attachment(String fileName, ContentType contentType)
public Attachment(String fileName, ContentType contentType)
Initializes a new instance of the Attachment class.
Parameters:
Parameter | Type | Description |
---|---|---|
fileName | java.lang.String | Name of the file. |
contentType | ContentType | The ContentType (AttachmentBase.getContentType/AttachmentBase.setContentType(ContentType)). |
Attachment(InputStream contentStream, String name)
public Attachment(InputStream contentStream, String name)
Initializes a new instance of the Attachment class.
Parameters:
Parameter | Type | Description |
---|---|---|
contentStream | java.io.InputStream | The content stream of attachment. |
name | java.lang.String | The attachment name. |
Attachment(InputStream contentStream, String name, String mediaType)
public Attachment(InputStream contentStream, String name, String mediaType)
Initializes a new instance of the Attachment class.
Parameters:
Parameter | Type | Description |
---|---|---|
contentStream | java.io.InputStream | The content stream of attachment. |
name | java.lang.String | The attachment name. |
mediaType | java.lang.String | The media type name. |
Attachment(InputStream contentStream, ContentType contentType)
public Attachment(InputStream contentStream, ContentType contentType)
Initializes a new instance of the Attachment class.
Parameters:
Parameter | Type | Description |
---|---|---|
contentStream | java.io.InputStream | The content stream of attachment. |
contentType | ContentType | The ContentType (AttachmentBase.getContentType/AttachmentBase.setContentType(ContentType)). |
close()
public void close()
createAttachmentFromString(String content, ContentType contentType)
public static Attachment createAttachmentFromString(String content, ContentType contentType)
Creates the attachment from string.
Parameters:
Parameter | Type | Description |
---|---|---|
content | java.lang.String | A string that represents the content of attachment. |
contentType | ContentType | The ContentType (AttachmentBase.getContentType/AttachmentBase.setContentType(ContentType)). |
Returns: Attachment - Returns created attachment
createAttachmentFromString(String content, String name)
public static Attachment createAttachmentFromString(String content, String name)
Creates the attachment from string.
Parameters:
Parameter | Type | Description |
---|---|---|
content | java.lang.String | A string that represents the content of attachment. |
name | java.lang.String | The attachment name. |
Returns: Attachment - Returns created attachment
createAttachmentFromString(String content, String name, Charset contentEncoding, String mediaType)
public static Attachment createAttachmentFromString(String content, String name, Charset contentEncoding, String mediaType)
Creates the attachment from string.
Parameters:
Parameter | Type | Description |
---|---|---|
content | java.lang.String | A string that represents the content of attachment. |
name | java.lang.String | The attachment name. |
contentEncoding | java.nio.charset.Charset | The content encoding. |
mediaType | java.lang.String | The media type name |
Returns: Attachment - Returns created attachment
dispose()
public final void dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
equals(Object arg0)
public boolean equals(Object arg0)
Parameters:
Parameter | Type | Description |
---|---|---|
arg0 | java.lang.Object |
Returns: boolean
getClass()
public final native Class<?> getClass()
Returns: java.lang.Class
getContentDisposition()
public final ContentDisposition getContentDisposition()
Gets Content-Disposition header
Returns: ContentDisposition
getContentId()
public final String getContentId()
Gets or sets the content id.
Value: The content id.
Returns: java.lang.String
getContentStream()
public final InputStream getContentStream()
Gets or sets the content stream.
Value: The content stream.
Returns: java.io.InputStream
getContentType()
public final ContentType getContentType()
Gets or sets the type of the content.
Value: The type of the content.
Returns: ContentType
getHeaders()
public HeaderCollection getHeaders()
Gets headers collection of attachment.
Returns: HeaderCollection
getName()
public final String getName()
Gets or sets an attachment name
Returns: java.lang.String
getNameEncoding()
public final Charset getNameEncoding()
Gets or sets an encoding of attachment name
Returns: java.nio.charset.Charset
getPreferredTextEncoding()
public final Charset getPreferredTextEncoding()
Gets or sets a preferred text encoding
Returns: java.nio.charset.Charset
getTransferEncoding()
public final int getTransferEncoding()
Gets or sets the transfer encoding.
Value: The transfer encoding.
Returns: int
hashCode()
public native int hashCode()
Returns: int
isEmbeddedMessage()
public final boolean isEmbeddedMessage()
Gets a value indicating whether the attachment is an embedded message.
Returns: boolean
isTnef()
public final boolean isTnef()
Gets a value indicating whether the attachment is TNEF formatted message.
Returns: boolean
isUri()
public final boolean isUri()
Gets a value indicating whether attachment is URI-attachment.
Returns: boolean
notify()
public final native void notify()
notifyAll()
public final native void notifyAll()
save(OutputStream stream)
public void save(OutputStream stream)
Saves the specified stream.
Parameters:
Parameter | Type | Description |
---|---|---|
stream | java.io.OutputStream | The stream. |
save(String fileName)
public void save(String fileName)
Saves the specified file name.
Parameters:
Parameter | Type | Description |
---|---|---|
fileName | java.lang.String | Name of the file. |
setContentId(String value)
public final void setContentId(String value)
Gets or sets the content id.
Value: The content id.
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.lang.String |
setContentStream(InputStream value)
public final void setContentStream(InputStream value)
Gets or sets the content stream.
Value: The content stream.
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.io.InputStream |
setContentType(ContentType value)
public final void setContentType(ContentType value)
Gets or sets the type of the content.
Value: The type of the content.
Parameters:
Parameter | Type | Description |
---|---|---|
value | ContentType |
setName(String value)
public final void setName(String value)
Gets or sets an attachment name
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.lang.String |
setNameEncoding(Charset value)
public final void setNameEncoding(Charset value)
Gets or sets an encoding of attachment name
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.nio.charset.Charset |
setPreferredTextEncoding(Charset value)
public final void setPreferredTextEncoding(Charset value)
Gets or sets a preferred text encoding
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.nio.charset.Charset |
setTransferEncoding(int value)
public final void setTransferEncoding(int value)
Gets or sets the transfer encoding.
Value: The transfer encoding.
Parameters:
Parameter | Type | Description |
---|---|---|
value | int |
toString()
public String toString()
Returns: java.lang.String
wait()
public final void wait()
wait(long arg0)
public final native void wait(long arg0)
Parameters:
Parameter | Type | Description |
---|---|---|
arg0 | long |
wait(long arg0, int arg1)
public final void wait(long arg0, int arg1)
Parameters:
Parameter | Type | Description |
---|---|---|
arg0 | long | |
arg1 | int |