Reference Solutions Tutorials Visual Designer
    • REST API
      • Overview
        • API Endpoint
        • Authentication
        • Requests
        • Responses
        • Paging
      • Voice
        • Available Phone Numbers
        • Calls
          • Call List Resource URI
          • Making a Call
          • Modifying Live Calls
          • Examples
          • List Filter
          • Paging Information
        • Clients
          • Create a Client
          • Delete a Client
          • Change Client’s Password
          • Get a List of Available Clients
        • Conference Management
          • Supported Operations
          • Conference List Resource URI
        • Conference Participants Management
          • Participants List Resource URI
        • Incoming Phone Numbers
          • IncomingPhoneNumber Instance Resource
          • IncomingPhoneNumbers List Resource
          • Local IncomingPhoneNumber Factory Resource
          • Toll-Free IncomingPhoneNumber Factory Resource
          • Mobile IncomingPhoneNumber Factory Resource
          • Attach a phone number to an application
          • Delete a phone number
          • List of Phone Numbers
          • Incoming Phone Number Regex Support
        • Recordings
        • SIP Refer Support
      • SMS
        • Available Phone Numbers
        • Clients
          • Create a Client
          • Delete a Client
          • Change Client’s Password
          • Get a List of Available Clients
        • Incoming Phone Numbers
          • IncomingPhoneNumber Instance Resource
          • IncomingPhoneNumbers List Resource
          • Local IncomingPhoneNumber Factory Resource
          • Toll-Free IncomingPhoneNumber Factory Resource
          • Mobile IncomingPhoneNumber Factory Resource
          • Attach a phone number to an application
          • Delete a phone number
          • List of Phone Numbers
          • Incoming Phone Number Regex Support
        • Messages
          • Send SMS
          • Get SMS List
          • Get single SMS Information
          • SMS Attributes
        • Email
      • Accounts
      • Applications
      • Notifications
      • Usage Records
    • RCML
      • Overview
        • How wlparam:replace[textMode="sps",parmText="application_name",text="Restcomm",defaultText="$INFER_FROM_DOMAIN"
        • RCML Verbs
      • Dial
        • Client
        • Conference
        • Number
        • SIP
      • Email
      • Gather
      • Say
      • Play
      • SMS
      • Hangup
      • Pause
      • Redirect
      • Record
      • Reject
    • Solution APIs
      • Two-Factor Authentication (2FA)
docs 1.0
  • docs
    • 1.0
  • docs
  • Enterprise:REST API
  • Enterprise:SMS
  • Enterprise:Email

Email

Email

Using the Restcomm API, you can send Emails through a simple request.

Email resource URI

/2012-04-24/Accounts/{AccountSid}/Email/Messages

Send a new email and get email details

HTTP POST. Sends a new Email message and returns the representation of the Email message resource, including the properties above. Below you will find a list of required and optional parameters.

Request Parameters

Parameter Description

From(Required)

The Email address to use as sender address.

To(Required)

The destination Email address.

Body(Required)

The body of the Email message.

Subject(Required)

The subject of the Email message.(Max. 160 chars.)

Type

The value to be used in the Content-Type header of the email message. (eg text/html for HTML emails)

BCC

The Blind Carbon Copy feature (Bcc).  (Hide addresses when sending an Email to various recipients)

CC

The Carbon Copy (Cc). (The list of CCed recipients is visible to all other recipients of the message.)

Examples

curl -X POST https://mycompany.restcomm.com/restcomm/2012-04-24/Accounts/ACCOUNT_SID/Email/Messages.xml  \
   -d 'To=email@hotmail.com' \
   -d 'From=email@gmail.com' \
   -d 'Body=This is a test' \
   -d 'Subject=Test Email' \
   -u 'YourAccountSid:YourAuthToken'
const request = require('request');

// Provide your Account Sid and Auth Token from your Console Account page
const ACCOUNT_SID = 'my_ACCOUNT_SID';
const AUTH_TOKEN = 'my_AUTH_TOKEN';

request.({
      method: 'POST',
      url: 'https://mycompany.restcomm.com/restcomm/2012-04-24/Accounts/' + ACCOUNT_SID + '/Email/Messages.xml',
      auth: { 'user': ACCOUNT_SID, 'pass': AUTH_TOKEN },
      form: {
         'To': 'email@hotmail.com',
         'From': 'email@gmail.com',
         'Body': 'This is a test',
         'Subject': 'Test Email'
      }
   },
   function (error, response, body) {
      // Add your business logic below; status can be found at 'response.statusCode' and response body at 'body'
      ...
});
from http.client import HTTPSConnection
from base64 import b64encode
from urllib.parse import urlencode

# Provide your Account Sid and Auth Token from your Console Account page
ACCOUNT_SID = 'my_ACCOUNT_SID'
AUTH_TOKEN = 'my_AUTH_TOKEN'

userAndPass = b64encode(bytes(ACCOUNT_SID + ':' + AUTH_TOKEN, 'utf-8')).decode("ascii")
headers = { 'Authorization' : 'Basic %s' %  userAndPass,
    'Content-type': 'application/x-www-form-urlencoded',
    'Accept': 'text/plain' }

# Update POST parameters accordingly
params = urlencode({
   'To': 'email@hotmail.com',
   'From': 'email@gmail.com',
   'Body': 'This is a test',
   'Subject': 'Test Email'
})

conn = HTTPSConnection('mycompany.restcomm.com')
conn.request("POST", '/restcomm/2012-04-24/Accounts/' + ACCOUNT_SID + '/Email/Messages.xml',
      params, headers=headers)
res = conn.getresponse()

# Add your business logic below; status can be found at 'res.status', reason at 'res.reason' and response body can be retrieved with res.read()
...
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.util.Base64;

public class JavaSampleClass {
   // Provide your Account Sid and Auth Token from your Console Account page
   public static final String ACCOUNT_SID = "my_ACCOUNT_SID";
   public static final String AUTH_TOKEN = "my_AUTH_TOKEN";


   public static void main(String[] args) throws Exception {
      String userAndPass = ACCOUNT_SID + ':' + AUTH_TOKEN;
      String encoded = Base64.getEncoder().encodeToString(userAndPass.getBytes());

      URL url = new URL(("https://mycompany.restcomm.com/restcomm/2012-04-24/Accounts/" + ACCOUNT_SID + "/Email/Messages.xml");
      HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
      conn.setRequestProperty("Authorization", "Basic " + encoded);
      conn.setRequestMethod("POST");
      conn.setDoOutput(true);
      DataOutputStream os = new DataOutputStream(conn.getOutputStream());

      // Update POST parameters accordingly
      os.writeBytes("To=email@hotmail.com&" +
        "From=email@gmail.com&" +
        "Body=This is a test&" +
        "Subject=Test Email");
      os.close();

      // Add your business logic below; response code can be obtained from 'conn.getResponseCode()' and input stream from 'conn.getInputStream()'
      ...
  }
}

Using Email

You need to configure Restcomm to send Email messages. For the necessary configuration please refer to this post

Example POST Response - XML and JSON

  • XML POST Response

curl -X POST https://mycompany.restcomm.com/restcomm/2012-04-24/Accounts/ACCOUNT_SID/Email/Messages.xml  \
   -d 'To=email@hotmail.com' \
   -d 'From=email@gmail.com' \
   -d 'Body=This is a test' \
   -d 'Subject=Test Email' \
   -u 'YourAccountSid:YourAuthToken'
const request = require('request');

// Provide your Account Sid and Auth Token from your Console Account page
const ACCOUNT_SID = 'my_ACCOUNT_SID';
const AUTH_TOKEN = 'my_AUTH_TOKEN';

request.({
      method: 'POST',
      url: 'https://mycompany.restcomm.com/restcomm/2012-04-24/Accounts/' + ACCOUNT_SID + '/Email/Messages.xml',
      auth: { 'user': ACCOUNT_SID, 'pass': AUTH_TOKEN },
      form: {
         'To': 'email@hotmail.com',
         'From': 'email@gmail.com',
         'Body': 'This is a test',
         'Subject': 'Test Email'
      }
   },
   function (error, response, body) {
      // Add your business logic below; status can be found at 'response.statusCode' and response body at 'body'
      ...
});
from http.client import HTTPSConnection
from base64 import b64encode
from urllib.parse import urlencode

# Provide your Account Sid and Auth Token from your Console Account page
ACCOUNT_SID = 'my_ACCOUNT_SID'
AUTH_TOKEN = 'my_AUTH_TOKEN'

userAndPass = b64encode(bytes(ACCOUNT_SID + ':' + AUTH_TOKEN, 'utf-8')).decode("ascii")
headers = { 'Authorization' : 'Basic %s' %  userAndPass,
    'Content-type': 'application/x-www-form-urlencoded',
    'Accept': 'text/plain' }

# Update POST parameters accordingly
params = urlencode({
   'To': 'email@hotmail.com',
   'From': 'email@gmail.com',
   'Body': 'This is a test',
   'Subject': 'Test Email'
})

conn = HTTPSConnection('mycompany.restcomm.com')
conn.request("POST", '/restcomm/2012-04-24/Accounts/' + ACCOUNT_SID + '/Email/Messages.xml',
      params, headers=headers)
res = conn.getresponse()

# Add your business logic below; status can be found at 'res.status', reason at 'res.reason' and response body can be retrieved with res.read()
...
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.util.Base64;

public class JavaSampleClass {
   // Provide your Account Sid and Auth Token from your Console Account page
   public static final String ACCOUNT_SID = "my_ACCOUNT_SID";
   public static final String AUTH_TOKEN = "my_AUTH_TOKEN";


   public static void main(String[] args) throws Exception {
      String userAndPass = ACCOUNT_SID + ':' + AUTH_TOKEN;
      String encoded = Base64.getEncoder().encodeToString(userAndPass.getBytes());

      URL url = new URL(("https://mycompany.restcomm.com/restcomm/2012-04-24/Accounts/" + ACCOUNT_SID + "/Email/Messages.xml");
      HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
      conn.setRequestProperty("Authorization", "Basic " + encoded);
      conn.setRequestMethod("POST");
      conn.setDoOutput(true);
      DataOutputStream os = new DataOutputStream(conn.getOutputStream());

      // Update POST parameters accordingly
      os.writeBytes("To=email@hotmail.com&" +
        "From=email@gmail.com&" +
        "Body=This is a test&" +
        "Subject=Test Email");
      os.close();

      // Add your business logic below; response code can be obtained from 'conn.getResponseCode()' and input stream from 'conn.getInputStream()'
      ...
  }
}
<RestcommResponse>
  <EmailMessage>
    <DateSent>2016-02-07T23:43:03.910Z</DateSent>
    <AccountSid>ACae6e420f425248d6a26948c17a9e2acf</AccountSid>
    <From>email@gmail.com</From>
    <To>email@hotmail.com</To>
    <Body>This is a test</Body>
    <Subject>Test Email</Subject>
  </EmailMessage>
  • JSON POST Response

curl -X POST https://mycompany.restcomm.com/restcomm/2012-04-24/Accounts/ACCOUNT_SID/Email/Messages.json  \
   -d 'To=email@hotmail.com' \
   -d 'From=email@gmail.com' \
   -d 'Body=This is a test ' \
   -d 'Subject=Test Email' \
   -u 'YourAccountSid:YourAuthToken'
const request = require('request');

// Provide your Account Sid and Auth Token from your Console Account page
const ACCOUNT_SID = 'my_ACCOUNT_SID';
const AUTH_TOKEN = 'my_AUTH_TOKEN';

request.({
      method: 'POST',
      url: 'https://mycompany.restcomm.com/restcomm/2012-04-24/Accounts/' + ACCOUNT_SID + '/Email/Messages.json',
      auth: { 'user': ACCOUNT_SID, 'pass': AUTH_TOKEN },
      form: {
         'To': 'email@hotmail.com',
         'From': 'email@gmail.com',
         'Body': 'This is a test ',
         'Subject': 'Test Email'
      }
   },
   function (error, response, body) {
      // Add your business logic below; status can be found at 'response.statusCode' and response body at 'body'
      ...
});
from http.client import HTTPSConnection
from base64 import b64encode
from urllib.parse import urlencode

# Provide your Account Sid and Auth Token from your Console Account page
ACCOUNT_SID = 'my_ACCOUNT_SID'
AUTH_TOKEN = 'my_AUTH_TOKEN'

userAndPass = b64encode(bytes(ACCOUNT_SID + ':' + AUTH_TOKEN, 'utf-8')).decode("ascii")
headers = { 'Authorization' : 'Basic %s' %  userAndPass,
    'Content-type': 'application/x-www-form-urlencoded',
    'Accept': 'text/plain' }

# Update POST parameters accordingly
params = urlencode({
   'To': 'email@hotmail.com',
   'From': 'email@gmail.com',
   'Body': 'This is a test ',
   'Subject': 'Test Email'
})

conn = HTTPSConnection('mycompany.restcomm.com')
conn.request("POST", '/restcomm/2012-04-24/Accounts/' + ACCOUNT_SID + '/Email/Messages.json',
      params, headers=headers)
res = conn.getresponse()

# Add your business logic below; status can be found at 'res.status', reason at 'res.reason' and response body can be retrieved with res.read()
...
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.util.Base64;

public class JavaSampleClass {
   // Provide your Account Sid and Auth Token from your Console Account page
   public static final String ACCOUNT_SID = "my_ACCOUNT_SID";
   public static final String AUTH_TOKEN = "my_AUTH_TOKEN";


   public static void main(String[] args) throws Exception {
      String userAndPass = ACCOUNT_SID + ':' + AUTH_TOKEN;
      String encoded = Base64.getEncoder().encodeToString(userAndPass.getBytes());

      URL url = new URL(("https://mycompany.restcomm.com/restcomm/2012-04-24/Accounts/" + ACCOUNT_SID + "/Email/Messages.json");
      HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
      conn.setRequestProperty("Authorization", "Basic " + encoded);
      conn.setRequestMethod("POST");
      conn.setDoOutput(true);
      DataOutputStream os = new DataOutputStream(conn.getOutputStream());

      // Update POST parameters accordingly
      os.writeBytes("To=email@hotmail.com&" +
        "From=email@gmail.com&" +
        "Body=This is a test &" +
        "Subject=Test Email");
      os.close();

      // Add your business logic below; response code can be obtained from 'conn.getResponseCode()' and input stream from 'conn.getInputStream()'
      ...
  }
}
{
  "date_sent": "2016-02-07T23:54:41.293Z",
  "account_sid": "ACae6e420f425248d6a26948c17a9e2acf",
  "from": "email@gmail.com",
  "to": "email@hotmail.com",
  "body": "This is a test",
  "subject": "Test Email"
}

Email Attributes

Attribute Description

DateSent

The date that this Email Message was send.

AccountSid

The unique id of the Account that sent this Email message.

From

The Email address that initiated the message.

To

The Email address of the recipient.

Body

The text body of the email message.

Subject

The subject of the email message.

Products

Programmable Voice

Programmable SMS

Use Cases

Two-Factor Authentication (2FA)

Phone Number Masking

Voicemail to Email Application

Learn

Terms And Conditions

Contact us

Telestax