Skip to content

Sending Email

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.

Configuration

To configure the 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
    email-settings.zoom50


where:

  • 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 Reset 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.

// *******************************************
// synchronous methods
// *******************************************
Backendless.Messaging.sendTextEmail( String subject, 
                                     String messageBody, 
                                     List<String> recipients )
Backendless.Messaging.sendTextEmail( String subject, 
                                     String messageBody, 
                                     String recipient )
Backendless.Messaging.sendHTMLEmail( String subject, 
                                     String messageBody, 
                                     List<String> recipients )
Backendless.Messaging.sendHTMLEmail( String subject, 
                                     String messageBody, 
                                     String recipient )
Backendless.Messaging.sendEmail( String subject, 
                                 BodyParts bodyParts, 
                                 String recipient, 
                                 List<String> attachments )
Backendless.Messaging.sendEmail( String subject, 
                                 BodyParts bodyParts, 
                                 String recipient )
Backendless.Messaging.sendEmail( String subject, 
                                 BodyParts bodyParts, 
                                 List<String> recipients, 
                                 List<String> attachments )

// *******************************************
// asynchronous methods
// *******************************************
Backendless.Messaging.sendTextEmail( String subject, 
                                     String messageBody, 
                                     List<String> recipients, 
                                     AsyncCallback<Void> responder );
Backendless.Messaging.sendTextEmail( String subject, 
                                     String messageBody, 
                                     String recipient, 
                                     AsyncCallback<Void> responder );
Backendless.Messaging.sendHTMLEmail( String subject, 
                                     String messageBody, 
                                     List<String> recipients, 
                                     AsyncCallback<Void> responder );
Backendless.Messaging.sendHTMLEmail( String subject, 
                                     String messageBody, 
                                     String recipient, 
                                     AsyncCallback<Void> responder );
Backendless.Messaging.sendEmail( String subject, 
                                 BodyParts bodyParts, 
                                 String recipient, 
                                 List<String> attachments, 
                                 AsyncCallback<Void> responder );
Backendless.Messaging.sendEmail( String subject, 
                                 BodyParts bodyParts, 
                                 String recipient, 
                                 AsyncCallback<Void> responder );
Backendless.Messaging.sendEmail( String subject, 
                                 BodyParts bodyParts, 
                                 List<String> recipients, 
                                 List<String> attachments, 
                                 AsyncCallback<Void> responder );

where:

Argument                Description
subject email message subject.
messageBody plain text or HTML body of the email message.
bodyParts an instance of com.backendless.messaging.BodyParts class which contains either plain text and/or HTML version of the message body.
recipient email address to deliver the email message to.
recipients a collection 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.

Example

// **************************************************************
// Async API request
// **************************************************************
AsyncCallback<Void> responder = new AsyncCallback<Void>()
{
  @Override
  public void handleResponse( Void response )
  {
    Log.i( "MYAPP", "[ASYNC] email has been sent" );
  }

  @Override
  public void handleFault( BackendlessFault fault )
  {
    Log.e( "MYAPP", "error sending email - " + fault.getMessage() );
  }
};

Backendless.Messaging.sendTextEmail( "Reminder", 
                                     "Hey JB! Your car will be ready by 5pm", 
                                     "james.bond@mi6.co.uk", 
                                     responder );

// **************************************************************
// Sync API request. HTML messahe to multiple recipients
// **************************************************************
ArrayList<String> recipients = new ArrayList<String>();
recipients.add( "mom@gmail.com" );
recipients.add( "dad@gmail.com" );

String mailBody = "Guys, the dinner last night was <b>awesome</b>";

Backendless.Messaging.sendHTMLEmail( "Dinner", mailBody, recipients );

Log.i( "MYAPP", "[SYNC] email has been sent" );