# Class Message

java.lang.Object
com.codename1.messaging.Message

public class Message extends Object

Represents a message to be sent using underlying platform e-mail client or the cloud.

The code below demonstrates sending a simple message with attachments using the devices native email client:

    Message m = new Message("Body of message");
    m.getAttachments().put(textAttachmentUri, "text/plain");
    m.getAttachments().put(imageAttachmentUri, "image/png");
    Display.getInstance().sendMessage(new String[] {"someone@gmail.com"}, "Subject of message", m);

The following code demonstrates sending an email via the Codename One cloud, notice that this is a pro specific feature:

    Message m = new Message("Check out Codename One");
    m.setMimeType(Message.MIME_HTML);

    // notice that we provide a plain text alternative as well in the send method
    boolean success = m.sendMessageViaCloudSync("Codename One", "destination@domain.com", "Name Of User", "Message Subject",
                                "Check out Codename One at https://www.codenameone.com/");

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `MIME_HTML`
  `static final String`
  `MIME_IMAGE_JPG`
  `static final String`
  `MIME_IMAGE_PNG`
  `static final String`
  `MIME_TEXT`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Message(String content)`
  Constructor with the message body content

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `getAttachment()`
  Gets the message attachment file path
  `String`
  `getAttachmentMimeType()`
  Gets the attachment mime type
  `Map<String,String>`
  `getAttachments()`
  Returns the attachment map which can be used to add multiple attachments.
  `String`
  `getContent()`
  Gets the message content
  `String`
  `getMimeType()`
  Gets the message mime type
  `boolean`
  `isCloudMessageFailSilently()`
  Indicates whether the cloud message should produce an error dialog if sending failed
  `static void`
  `sendMessage(String[] recipients, String subject, Message msg)`
  Send an email using the platform mail client
  `void`
  `sendMessageViaCloud(String sender, String recipient, String recipientName, String subject, String plainTextBody)`
  Send an email message using the Codename One cloud to send the message, notice that this API will only work for pro accounts.
  `boolean`
  `sendMessageViaCloudSync(String sender, String recipient, String recipientName, String subject, String plainTextBody)`
  Send an email message using the Codename One cloud to send the message, notice that this API will only work for pro accounts.
  `void`
  `setAttachment(String fileUri)`
  Sets the message attachment if exists
  `void`
  `setAttachmentMimeType(String mimeType)`
  Sets the attachment mime type.
  `void`
  `setCloudMessageFailSilently(boolean cloudMessageFailSilently)`
  Indicates whether the cloud message should produce an error dialog if sending failed
  `void`
  `setMimeType(String mimeType)`
  Sets the message mime type.

  ### Methods inherited from class Object

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

- ## Field Details

  - ### MIME_TEXT

    public static final String MIME_TEXT
    See Also:
      - Constant Field Values

  - ### MIME_HTML

    public static final String MIME_HTML
    See Also:
      - Constant Field Values

  - ### MIME_IMAGE_JPG

    public static final String MIME_IMAGE_JPG
    See Also:
      - Constant Field Values

  - ### MIME_IMAGE_PNG

    public static final String MIME_IMAGE_PNG
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### Message

    public Message(String content)

    Constructor with the message body content

    ###### Parameters

    - `content`: the message content

- ## Method Details

  - ### sendMessage

    public static void sendMessage(String[] recipients, String subject, Message msg)

    Send an email using the platform mail client

    ###### Parameters

    - `recipients`: array of e-mail addresses

    - `subject`: e-mail subject

    - `msg`: the Message to send

  - ### getContent

    public String getContent()

    Gets the message content

    ###### Returns

    content

  - ### getAttachments

    public Map<String,String> getAttachments()

    Returns the attachment map which can be used to add multiple attachments. The path needs to point at a full absolute file URI within `com.codename1.io.FileSystemStorage`, it will not work with `com.codename1.io.Storage` files!

    ###### Returns

    a map of full file paths to mime type that can be used to add attachments

  - ### getMimeType

    public String getMimeType()

    Gets the message mime type

    ###### Returns

    the mime type

  - ### setMimeType

    public void setMimeType(String mimeType)

    Sets the message mime type.

    ###### Parameters

    - `mimeType`

  - ### getAttachmentMimeType

    public String getAttachmentMimeType()
    Gets the attachment mime type

  - ### setAttachmentMimeType

    public void setAttachmentMimeType(String mimeType)

    Sets the attachment mime type.

    ###### Parameters

    - `mimeType`

  - ### getAttachment

    public String getAttachment()

    Gets the message attachment file path

    ###### Returns

    the file path of the attachment

  - ### setAttachment

    public void setAttachment(String fileUri)

    Sets the message attachment if exists

    ###### Parameters

    - `fileUri`: the file to attach to the message

  - ### sendMessageViaCloud

    public void sendMessageViaCloud(String sender, String recipient, String recipientName, String subject, String plainTextBody)

    Send an email message using the Codename One cloud to send the message, notice that this API will only work for pro accounts.

        Message m = new Message("Check out Codename One");
        m.setMimeType(Message.MIME_HTML);

        // notice that we provide a plain text alternative as well in the send method
        boolean success = m.sendMessageViaCloudSync("Codename One", "destination@domain.com", "Name Of User", "Message Subject",
                                    "Check out Codename One at https://www.codenameone.com/");

    ###### Parameters

    - `sender`: the name of the sender, notice all email will arrive from Codename One to avoid spam issues

    - `recipient`: the email for the recipient

    - `recipientName`: the display name for the recipient

    - `subject`: e-mail subject

    - `plainTextBody`: @param plainTextBody when sending an HTML message you should also attach a plain text fallback message, this is redundant if the email is a plain text message to begin with

    ###### Deprecated

    this functionality is retired and no longer works. You can use the sendgrid cn1lib or similar libraries

  - ### sendMessageViaCloudSync

    public boolean sendMessageViaCloudSync(String sender, String recipient, String recipientName, String subject, String plainTextBody)

    Send an email message using the Codename One cloud to send the message, notice that this API will only work for pro accounts.

        Message m = new Message("Check out Codename One");
        m.setMimeType(Message.MIME_HTML);

        // notice that we provide a plain text alternative as well in the send method
        boolean success = m.sendMessageViaCloudSync("Codename One", "destination@domain.com", "Name Of User", "Message Subject",
                                    "Check out Codename One at https://www.codenameone.com/");

    ###### Parameters

    - `sender`: the name of the sender, notice all email will arrive from Codename One to avoid spam issues

    - `recipient`: the email for the recipient

    - `recipientName`: the display name for the recipient

    - `subject`: e-mail subject

    - `plainTextBody`: @param plainTextBody when sending an HTML message you should also attach a plain text fallback message, this is redundant if the email is a plain text message to begin with

    ###### Returns

    true if sending succeeded

    ###### Deprecated

    this functionality is retired and no longer works. You can use the sendgrid cn1lib or similar libraries

  - ### isCloudMessageFailSilently

    public boolean isCloudMessageFailSilently()

    Indicates whether the cloud message should produce an error dialog if sending failed

    ###### Returns

    the cloudMessageFailSilently

  - ### setCloudMessageFailSilently

    public void setCloudMessageFailSilently(boolean cloudMessageFailSilently)

    Indicates whether the cloud message should produce an error dialog if sending failed

    ###### Parameters

    - `cloudMessageFailSilently`: the cloudMessageFailSilently to set