Sending Email

Top  Previous 

Backendless provides API for email delivery on behalf of your application. 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 if the Manage > App Settings > Email Settings section in Backendless Console contains default values.



To configure a backend:


1.Login to Backendless Console.
2.Select an app.
3.Click Manage, then scroll down to Email Settings on the App Settings screen.
4.Fill out the form with the SMTP server information


SMTP Server - Hostname or public IP address of the server where the SMTP server is running.
Port - The port number the SMTP server accepts requests on.
From - The Name which will appear in the From field of the sent out emails.
User ID- The user id or email address for the SMTP server connection authentication
Password- The password for the SMTP server connection authentication.
Security- Choose between SSL or TLS connection.


Make sure to click Test before saving any configuration changes. The Discard button discards any unsaved changes.


Sending Email API

Delivers an email message using current server-side email settings to the recipient specified in the API call.


Backendless.Messaging.sendEmail( subject, bodyParts, recipients, attachments, responder );


subject- email message subject.
bodyParts- an instance of Bodyparts,  which contains either plain text and/or HTML version of the message body.
recipients- an array of email addressed to deliver the email message to.
attachments- 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 (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".
responder- the callback used for asynchronous calls to indicate that the operation has either successfully completed or resulted in error.



var successCallback = function( response ) 
  console.log( "[ASYNC] message has been sent" );

var failureCallback = function( fault ) 
  console.log( "error - " + fault.message );

// prepare message bodies (plain and html) and attachment
var bodyParts = new Bodyparts();
bodyParts.textmessage = "Check out this awesome code generation result";
bodyParts.htmlmessage = "Check out this <b>awesome</b> code generation result";
var attachments = ["" ];

// asynchronous call
var responder = new Backendless.Async( successCallback, failureCallback );
Backendless.Messaging.sendEmail( "Backendless code gen", bodyParts, [ "" ], attachments, responder );
// same thing, but synchronously
Backendless.Messaging.sendEmail( "Backendless code gen", bodyParts, [ "" ], attachments );
console.log( "[SYNC] message has been sent" );


Please let us know how we can improve the documentation by leaving a comment. All technical questions should be posted to the Backendless Support forum. We do not respond to the technical questions on the documentation pages.: