Send Basic Emails API¶
Backendless provides API for basic email delivery. The API lets you specify:
- plain text and/or HTML-based content for your email messages;
- a list of email address for the recipient;
- a list of attachments;
Important
Before the API can be used, the Backendless backend must be configured with your own SMTP server information. This is an important requirement as the API will not work when the Manage > App Settings > Email Settings section in Backendless Console contains default values. For instructions on how to configure your own SMTP server in Backendless, see the Email Settings section.
Sending Email API¶
Delivers an email message to the recipient(s) specified in the API call.
Method:¶
POST
Endpoint URL¶
The xxxx.backendless.app
is a subdomain assigned to your application. For more information see the Client-side Setup section of this documentation.
https://xxxx.backendless.app/api/messaging/email
Request headers¶
Content-Type: application/json
user-token: optional value obtained as a result of the login operation.
where:
Argument | Description |
---|---|
Content-Type |
Must be set to application/json . This header is mandatory. |
user-token |
Optional header. Contains a value returned by Backendless in a preceding user Login API call. If user-token is set in the request, the currently logged in user will be assigned to the ownerId property of the user object which is being saved. Additionally, the operation will be executed with the security policy associated currently logged in user. This means all permissions associated with the user and the roles assigned to the user will be enforced by Backendless. |
Request body¶
{
"subject" : value,
"bodyparts" : {
"textmessage" : value,
"htmlmessage" : value
},
"to" : [ array of values ],
"attachment" : [ array of file paths from the Backendless File Service ]
}
where:
Argument | Description |
---|---|
subject |
Email message subject. |
bodyparts.textmessage |
Plain text body of the email message. |
bodyparts.htmlmessage |
HTML version of the body of the email message. |
to |
An array of email addresses to deliver the email message to. |
attachment |
An array of file paths for the file entries from the Backendless File Service. Referenced files will be attached to the email message. The path is calculated from the root of the file system without the leading slash. For example if file agreement.txt is located at /documents/legal/, then the path in the REST request must be documents/legal/agreement.txt . |
Example¶
Important
Make sure to replace xxxx in the domain name in the sample request below to the one assigned to your application.
Sending basic email:
curl \
-H Content-Type:application/json \
-X POST \
-d '{"subject":"Hello World!", "bodyparts":{"textmessage":"This is an email message sent by Backendless"}, "to":["james.bond@mi6.co.uk"]}' https://xxxx.backendless.app/api/messaging/email
Sending an email with an attachment:
curl \
-H Content-Type:application/json \
-X POST \
-d '{ "subject": "Sample email with attachment", "bodyparts": { "textmessage":"Here's a sample attachment..." }, "attachment": [ "web/index.html" ], "to": [ "james.bond@mi6.co.uk" ] }' https://xxxx.backendless.app/api/messaging/email
Codeless Reference¶
where:
Argument | Description |
---|---|
subject |
Email message subject. |
body text/html |
Plain text or HTML body of the email message. |
recipient(s) |
A list containing email addresses to deliver the email message to. |
attachment(s) |
A list of file paths for the file entries from the Backendless File Service. Referenced files will be attached to the email message. The path is calculated from the root of the file system (as it is seen in File Service browser in Backendless console) without the leading slash. For example, if file agreement.txt is located at /documents/legal/ , then the path in the API call must be "documents/legal/agreement.txt". |
return result |
When this box is checked, the operation returns an object containing the status of the email delivery or an error. |
Returns an object containing the status of the email delivery or an error.
The example below sends an email to the "alice@yourmail.com"
with attachments leading to the files stored in the "/misc"
directory.