Skip to content

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.

All methods are non-blocking:

- (void)sendEmailWithSubject:(NSString * _Nonnull)subject
        bodyparts:(EmailBodyparts * _Nonnull)bodyparts
        recipients:(NSArray<NSString *> * _Nonnull)recipients
        attachments:(NSArray<NSString *> * _Nullable)attachments
        responseHandler:(void (^ _Null_unspecified)(MessageStatus * _Nonnull))responseHandler
        errorHandler:(void (^ _Null_unspecified)(Fault * _Nonnull))errorHandler;
func sendEmail(subject: String,
               bodyparts: EmailBodyparts,
               recipients: [String],
               attachments: [String]?,
               responseHandler: ((MessageStatus) -> Void)!,
               errorHandler: ((Fault) -> Void)!)

where:

Argument                Description
subject email message subject.
bodyParts an instance of the EmailBodyParts class which contains either plain text and/or HTML version of the message body.
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".

Example

NSString *subject = @"Hello from Backendless!";
NSString *recipient = @"james.bond@mi6.co.uk";

EmailBodyParts *bodyParts = [EmailBodyParts new];
bodyParts.htmlMessage = @"This is an email sent by API call from a Backendless backend";

[Backendless.shared.messaging
    sendEmailWithSubject:subject
    bodyParts:bodyParts
    recipients:@[recipient]
    attachments:@[@"documents/legal/agreement.txt", @"documents/schedule.pdf"]
    responseHandler:^(MessageStatus *status) {
        NSLog(@"HTML email has been sent");
    } errorHandler:^(Fault *fault) {
        NSLog(@"Error: %@", fault.message);
}];
let subject = "Hello from Backendless!"
let recipient = "james.bond@mi6.co.uk"

let bodyParts = EmailBodyParts()
bodyParts.htmlMessage = "This is an email sent by API call from a Backendless backend"

Backendless.shared.messaging.sendEmail(
    subject: subject,
    bodyParts: bodyParts,
    recipients: [recipient],
    attachments: ["documents/legal/agreement.txt", "documents/schedule.pdf"],
    responseHandler: { status in print("HTML email has been sent") },
    errorHandler: { fault in print("Error: \(fault.message ?? "")")
    })

Codeless Reference

email_api_send_email_1

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.

email_api_send_email_2