Class Message
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[] {"[email protected]"}, "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", "[email protected]", "Name Of User", "Message Subject",
"Check out Codename One at https://www.codenameone.com/");
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the message attachment file pathGets the attachment mime typeReturns the attachment map which can be used to add multiple attachments.Gets the message contentGets the message mime typebooleanIndicates whether the cloud message should produce an error dialog if sending failedstatic voidsendMessage(String[] recipients, String subject, Message msg) Send an email using the platform mail clientvoidsendMessageViaCloud(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.booleansendMessageViaCloudSync(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.voidsetAttachment(String fileUri) Sets the message attachment if existsvoidsetAttachmentMimeType(String mimeType) Sets the attachment mime type.voidsetCloudMessageFailSilently(boolean cloudMessageFailSilently) Indicates whether the cloud message should produce an error dialog if sending failedvoidsetMimeType(String mimeType) Sets the message mime type.
-
Field Details
-
MIME_TEXT
- See Also:
-
MIME_HTML
- See Also:
-
MIME_IMAGE_JPG
- See Also:
-
MIME_IMAGE_PNG
- See Also:
-
-
Constructor Details
-
Message
Constructor with the message body content
Parameters
content: the message content
-
-
Method Details
-
sendMessage
-
getContent
Gets the message content
Returns
content
-
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 withcom.codename1.io.Storagefiles!Returns
a map of full file paths to mime type that can be used to add attachments
-
getMimeType
Gets the message mime type
Returns
the mime type
-
setMimeType
Sets the message mime type.
Parameters
mimeType
-
getAttachmentMimeType
Gets the attachment mime type -
setAttachmentMimeType
Sets the attachment mime type.
Parameters
mimeType
-
getAttachment
Gets the message attachment file path
Returns
the file path of the attachment
-
setAttachment
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", "[email protected]", "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", "[email protected]", "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
-