# Class PstMessageWriter

java.lang.Object
com.independentsoft.pst.PstMessageWriter

public class PstMessageWriter extends Object
Represents a message to be created in a folder of a new PST file (write side).

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PstMessageWriter(String subject, String body)`
  Initializes a new instance of the `PstMessageWriter` class.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `PstAttachmentWriter`
  `addAttachment(String fileName, byte[] data)`
  Adds a file attachment and returns it.
  `ExtendedProperty`
  `addExtendedProperty(ExtendedProperty property)`
  Adds an extended (named) property and returns it.
  `PstRecipientWriter`
  `addRecipient(String displayName, String emailAddress)`
  Adds a "To" recipient and returns it.
  `List<PstAttachmentWriter>`
  `getAttachments()`
  Gets the attachments of this message.
  `String`
  `getBody()`
  Gets the plain-text body.
  `List<ExtendedProperty>`
  `getExtendedProperties()`
  Gets the extended (named) properties of this message.
  `String`
  `getMessageClass()`
  Gets the message class (default "IPM.Note").
  `List<PstRecipientWriter>`
  `getRecipients()`
  Gets the recipients of this message.
  `String`
  `getSubject()`
  Gets the subject.
  `void`
  `setBody(String body)`
  Sets the plain-text body.
  `void`
  `setMessageClass(String messageClass)`
  Sets the message class.
  `void`
  `setProperty(int propertyTag, boolean value)`
  Sets an arbitrary boolean property (type 0x000B).
  `void`
  `setProperty(int propertyTag, byte[] value)`
  Sets an arbitrary binary property (type 0x0102).
  `void`
  `setProperty(int propertyTag, int value)`
  Sets an arbitrary 32-bit integer property (e.g.
  `void`
  `setProperty(int propertyTag, long value)`
  Sets an arbitrary 64-bit integer property (type 0x0014).
  `void`
  `setProperty(int propertyTag, String value)`
  Sets an arbitrary string property.
  `void`
  `setProperty(int propertyTag, Date value)`
  Sets an arbitrary date/time property (type 0x0040 PtypTime), stored as a FILETIME (UTC).
  `void`
  `setSubject(String subject)`
  Sets the subject.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### PstMessageWriter

    public PstMessageWriter(String subject, String body)
    Initializes a new instance of the `PstMessageWriter` class.
    Parameters:
      `subject` - the message subject.
      `body` - the message body (plain text).

- ## Method Details

  - ### getSubject

    public String getSubject()
    Gets the subject.
    Returns:
      the subject.

  - ### setSubject

    public void setSubject(String subject)
    Sets the subject.
    Parameters:
      `subject` - the subject.

  - ### getBody

    public String getBody()
    Gets the plain-text body.
    Returns:
      the plain-text body.

  - ### setBody

    public void setBody(String body)
    Sets the plain-text body.
    Parameters:
      `body` - the plain-text body.

  - ### getMessageClass

    public String getMessageClass()
    Gets the message class (default "IPM.Note").
    Returns:
      the message class.

  - ### setMessageClass

    public void setMessageClass(String messageClass)
    Sets the message class.
    Parameters:
      `messageClass` - the message class.

  - ### getRecipients

    public List<PstRecipientWriter> getRecipients()
    Gets the recipients of this message.
    Returns:
      the recipients.

  - ### addRecipient

    public PstRecipientWriter addRecipient(String displayName, String emailAddress)
    Adds a "To" recipient and returns it.
    Parameters:
      `displayName` - the recipient display name.
      `emailAddress` - the recipient SMTP e-mail address.
    Returns:
      the created `PstRecipientWriter`.

  - ### getAttachments

    public List<PstAttachmentWriter> getAttachments()
    Gets the attachments of this message.
    Returns:
      the attachments.

  - ### addAttachment

    public PstAttachmentWriter addAttachment(String fileName, byte[] data)
    Adds a file attachment and returns it.
    Parameters:
      `fileName` - the attachment file name.
      `data` - the attachment content (currently must fit within a single block, ~7 KB).
    Returns:
      the created `PstAttachmentWriter`.

  - ### setProperty

    public void setProperty(int propertyTag, String value)
    Sets an arbitrary string property. The property tag is (propertyId << 16) | propertyType, e.g. 0x0037001F for PidTagSubject. Use a string type (0x001F Unicode, 0x001E ANSI).
    Parameters:
      `propertyTag` - the property tag.
      `value` - the string value.

  - ### setProperty

    public void setProperty(int propertyTag, int value)
    Sets an arbitrary 32-bit integer property (e.g. 0x00170003 PidTagImportance).
    Parameters:
      `propertyTag` - the property tag.
      `value` - the integer value.

  - ### setProperty

    public void setProperty(int propertyTag, long value)
    Sets an arbitrary 64-bit integer property (type 0x0014).
    Parameters:
      `propertyTag` - the property tag.
      `value` - the long value.

  - ### setProperty

    public void setProperty(int propertyTag, boolean value)
    Sets an arbitrary boolean property (type 0x000B).
    Parameters:
      `propertyTag` - the property tag.
      `value` - the boolean value.

  - ### setProperty

    public void setProperty(int propertyTag, Date value)
    Sets an arbitrary date/time property (type 0x0040 PtypTime), stored as a FILETIME (UTC).
    Parameters:
      `propertyTag` - the property tag.
      `value` - the date/time value.

  - ### setProperty

    public void setProperty(int propertyTag, byte[] value)
    Sets an arbitrary binary property (type 0x0102).
    Parameters:
      `propertyTag` - the property tag.
      `value` - the binary value.

  - ### getExtendedProperties

    public List<ExtendedProperty> getExtendedProperties()
    Gets the extended (named) properties of this message. Each `ExtendedProperty` is identified by an `ExtendedPropertyId` (numeric) or `ExtendedPropertyName` (string) under a property-set GUID; the PST's name-to-id map is extended automatically when the file is written.
    Returns:
      the extended properties.

  - ### addExtendedProperty

    public ExtendedProperty addExtendedProperty(ExtendedProperty property)
    Adds an extended (named) property and returns it.
    Parameters:
      `property` - the extended property to add.
    Returns:
      the added `ExtendedProperty`.