Forwarding Recordings to Your Email

It is possible to forward voicemail or other recordings made with Twilio's <Record> verb to your email inbox. This guide explains how to set this up.

Forward recordings with Twilio & SendGrid

Users can setup a cloud email forwarding application using Twilio Studio, Functions, and Send Grid. This method makes use of Twilio SendGrid, and our serverless products, meaning that there are no server or hosting requirements. It's also friendly for those who may not be developers, with all the code you'll need available for copy and paste.

The full instructions can be found here: Forward Voicemail Recordings to Email w/ Studio, Functions, & SendGrid (Twilio Blog).

Forward recordings with your own hosting

Users can also build an application for recording notifications using any language that works for them. Here's an example of a forwarding script in PHP - we'll call it mail.php:

<?php
header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>'; 
echo '<Response></Response>';
$to = "your-email@example.com"; // Update with your email address $subject = "Message from {$_REQUEST['From']}"; $message = "To listen to this message, please visit this URL: {$_REQUEST['RecordingUrl']}"; $headers = "From: webmaster@example.com"; // Update with your sending address mail($to, $subject, $message, $headers);

This script will respond to a Twilio request with an affirmative empty response, and then send an email with the following info:

  • To: The email will be sent to the email address in the 6th line of the code, labeled as $to - your-email@example.com in the sample code. Update this to the desired recipient.
  • Subject: The email subject will say Message from 3105551234, replacing this example phone number with that of the caller who recorded the message.
  • Body: The email body will say To listen to this message, please visit this URL: https://api.twilio.com/2010-04-01/Accounts/AC1234/Recordings/RE1234.mp3, replacing this example URL with that of your recording.
  • From: The email will be sent from the email address in the 9th line of the code, labeled as $headers - webmaster@example.com in the sample code. Update this to the desired sender.

Once mail.php has been posted to the internet, and is accessible by Twilio, use its URL as the value for your <Record> TwiML verb's action attribute. That should look something like this: 

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Record action="mail.php" />
</Response>

Legal Implications of Call Recording

If you choose to record calls, you need to comply with certain laws and regulations, including those regarding obtaining consent to record (such as California’s Invasion of Privacy Act and similar laws in other jurisdictions). Additional information on the legal implications of call recording can be found here.

Notice: Twilio recommends that you consult with your legal counsel to make sure that you are complying with all applicable laws in connection with communications you record or store using Twilio.

Have more questions? Submit a request
Powered by Zendesk