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:
The following code demonstrates sending an email via the Codename One cloud, notice that this is a pro specific feature:
Modifier and Type | Field and Description |
---|---|
static String |
MIME_HTML |
static String |
MIME_IMAGE_JPG |
static String |
MIME_IMAGE_PNG |
static String |
MIME_TEXT |
Constructor and Description |
---|
Message(String content)
Constructor with the message body content
|
Modifier and Type | Method and 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)
Deprecated.
this functionality is retired and no longer works. You can use the sendgrid cn1lib or similar libraries
|
boolean |
sendMessageViaCloudSync(String sender,
String recipient,
String recipientName,
String subject,
String plainTextBody)
Deprecated.
this functionality is retired and no longer works. You can use the sendgrid cn1lib or similar libraries
|
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.
|
public static final String MIME_TEXT
public static final String MIME_HTML
public static final String MIME_IMAGE_JPG
public static final String MIME_IMAGE_PNG
public Message(String content)
content
- the message contentpublic String getContent()
public void setAttachment(String fileUri)
fileUri
- the file to attach to the messagepublic Map<String,String> getAttachments()
FileSystemStorage
,
it will not work with Storage
files!public void setMimeType(String mimeType)
mimeType
- public String getMimeType()
public void setAttachmentMimeType(String mimeType)
mimeType
- public String getAttachmentMimeType()
public String getAttachment()
public static void sendMessage(String[] recipients, String subject, Message msg)
recipients
- array of e-mail addressessubject
- e-mail subjectmsg
- the Message to sendpublic 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.
sender
- the name of the sender, notice all email will arrive from Codename One to avoid spam issuesrecipient
- the email for the recipientrecipientName
- the display name for the recipientsubject
- e-mail subjectplainTextBody
- 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 withpublic 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.
sender
- the name of the sender, notice all email will arrive from Codename One to avoid spam issuesrecipient
- the email for the recipientrecipientName
- the display name for the recipientsubject
- e-mail subjectplainTextBody
- 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 withpublic boolean isCloudMessageFailSilently()
public void setCloudMessageFailSilently(boolean cloudMessageFailSilently)
cloudMessageFailSilently
- the cloudMessageFailSilently to set