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 accessible via the Backendless.Messaging:
// blocking methods
public void SendTextEmail( String subject, String messageBody, List<String> recipients );
public void SendTextEmail( String subject, String messageBody, String recipient );
public void SendHTMLEmail( String subject, String messageBody, List<String> recipients );
public void SendHTMLEmail( String subject, String messageBody, String recipient );
public void SendEmail( String subject, BodyParts bodyParts, String recipient, List<String> attachments );
public void SendEmail( String subject, BodyParts bodyParts, String recipient );
public void SendEmail( String subject, BodyParts bodyParts, List<String> recipients, List<String> attachments );
// non-blocking methods
public void SendTextEmail( String subject, String messageBody, List<String> recipients, AsyncCallback<object> responder );
public void SendTextEmail( String subject, String messageBody, String recipient, AsyncCallback<object> responder );
public void SendHTMLEmail( String subject, String messageBody, List<String> recipients, AsyncCallback<object> responder );
public void SendHTMLEmail( String subject, String messageBody, String recipient, AsyncCallback<object> responder );
public void SendEmail( String subject, BodyParts bodyParts, String recipient, List<String> attachments, AsyncCallback<object> responder );
public void SendEmail( String subject, BodyParts bodyParts, String recipient, AsyncCallback<object> responder );
public void SendEmail( String subject, BodyParts bodyParts, List<String> recipients, List<String> attachments, AsyncCallback<object> 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¶
AsyncCallback<object> responder = new AsyncCallback<object>(
result =>
{
System.Console.WriteLine( "[ASYNC] message sent" );
},
fault =>
{
System.Console.WriteLine( "Error - " + fault );
} );
// async request. Plain text message to one recipient
Backendless.Messaging.SendTextEmail( "Reminder", "Hey JB! Your car will be ready by 5pm", "james.bond@mi6.co.uk", responder );
// sync request. HTML messahe to multiple recipients
List<String> recipients = new List<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 );
System.Console.WriteLine( "[SYNC] email has been sent" );
Example - With The attachments Parameter¶
List<String> addresses = new List<String> { "joe@yahoo.com", "bob@hotmail.com"};
BodyParts mailBody = new BodyParts("text message", "html message");
List<String> attachments = new List<String> { "path/to/first/file.txt", "path/to/second/file.pdf" };
Backendless.Messaging.SendEmail("subject of message", mailBody, addresses, attachments);
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.