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

ConstructorDescription
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

MethodDescription
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:

ParameterTypeDescription
fileNamejava.lang.StringName of the file.

Attachment(String fileName, String mediaType)

public Attachment(String fileName, String mediaType)

Initializes a new instance of the Attachment class.

Parameters:

ParameterTypeDescription
fileNamejava.lang.StringName of the file.
mediaTypejava.lang.StringType media type name.

Attachment(String fileName, ContentType contentType)

public Attachment(String fileName, ContentType contentType)

Initializes a new instance of the Attachment class.

Parameters:

ParameterTypeDescription
fileNamejava.lang.StringName of the file.
contentTypeContentTypeThe 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:

ParameterTypeDescription
contentStreamjava.io.InputStreamThe content stream of attachment.
namejava.lang.StringThe 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:

ParameterTypeDescription
contentStreamjava.io.InputStreamThe content stream of attachment.
namejava.lang.StringThe attachment name.
mediaTypejava.lang.StringThe media type name.

Attachment(InputStream contentStream, ContentType contentType)

public Attachment(InputStream contentStream, ContentType contentType)

Initializes a new instance of the Attachment class.

Parameters:

ParameterTypeDescription
contentStreamjava.io.InputStreamThe content stream of attachment.
contentTypeContentTypeThe 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:

ParameterTypeDescription
contentjava.lang.StringA string that represents the content of attachment.
contentTypeContentTypeThe 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:

ParameterTypeDescription
contentjava.lang.StringA string that represents the content of attachment.
namejava.lang.StringThe 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:

ParameterTypeDescription
contentjava.lang.StringA string that represents the content of attachment.
namejava.lang.StringThe attachment name.
contentEncodingjava.nio.charset.CharsetThe content encoding.
mediaTypejava.lang.StringThe 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:

ParameterTypeDescription
arg0java.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:

ParameterTypeDescription
streamjava.io.OutputStreamThe stream.

save(String fileName)

public void save(String fileName)

Saves the specified file name.

Parameters:

ParameterTypeDescription
fileNamejava.lang.StringName of the file.

setContentId(String value)

public final void setContentId(String value)

Gets or sets the content id.

Value: The content id.

Parameters:

ParameterTypeDescription
valuejava.lang.String

setContentStream(InputStream value)

public final void setContentStream(InputStream value)

Gets or sets the content stream.

Value: The content stream.

Parameters:

ParameterTypeDescription
valuejava.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:

ParameterTypeDescription
valueContentType

setName(String value)

public final void setName(String value)

Gets or sets an attachment name

Parameters:

ParameterTypeDescription
valuejava.lang.String

setNameEncoding(Charset value)

public final void setNameEncoding(Charset value)

Gets or sets an encoding of attachment name

Parameters:

ParameterTypeDescription
valuejava.nio.charset.Charset

setPreferredTextEncoding(Charset value)

public final void setPreferredTextEncoding(Charset value)

Gets or sets a preferred text encoding

Parameters:

ParameterTypeDescription
valuejava.nio.charset.Charset

setTransferEncoding(int value)

public final void setTransferEncoding(int value)

Gets or sets the transfer encoding.

Value: The transfer encoding.

Parameters:

ParameterTypeDescription
valueint

toString()

public String toString()

Returns: java.lang.String

wait()

public final void wait()

wait(long arg0)

public final native void wait(long arg0)

Parameters:

ParameterTypeDescription
arg0long

wait(long arg0, int arg1)

public final void wait(long arg0, int arg1)

Parameters:

ParameterTypeDescription
arg0long
arg1int