Doppler Relay
Sign Up

Quick Examples

PHP Example

See a working PHP example in our GitHub repository

$apikey = "MY-API-KEY";
$accountId = 123;
$accountName = "MY-ACCOUNT-NAME";

$url = "https://api.dopplerrelay.com/accounts/$accountId/messages";

$data = array(
  'from_name' => 'Your Name',
  'from_email' => '[email protected]',
  'recipients' => array(
    array(
      'type' => 'to',
      'email' => '[email protected]',
      'name' => 'Test Recipient'
    )
  ),
  'subject' => 'Testing Doppler Relay',
  'html' => '<a href="https://www.dopplerrelay.com/">Doppler Relay</a> is great!'
);

$options = array(
  'http' => array(
    'header' => "Authorization: token $apikey\r\nContent-type: application/json\r\n",
    'method' => 'POST',
    'content' => json_encode($data)
  )
);

$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
var_dump($result);

.NET Example

See a complete .NET example solution in our GitHub repository

using Flurl.Http; // See https://www.nuget.org/packages/Flurl.Http/
using System.Threading.Tasks;

class Program
{
  // UPDATE THESE VALUES:
  const string Apikey = "MY-API-KEY";
  const int AccountId = 123;
  const string AccountName = "MY-ACCOUNT-NAME";

  static async Task MainAsync()
  {
    var url = $"https://api.dopplerrelay.com/accounts/{AccountId}/messages";
    var client = new FlurlClient(url).WithOAuthBearerToken(Apikey);
    var request = client.Request();

    var requestBody = new
    {
      from_name = "From Name",
      from_email = "[email protected]",
      recipients = new[]
      {
        new
        {
          email = "[email protected]",
          name = "To Name",
          type = "to"
        }
      },
      subject = "Email subject",
      html = "<a href=\"https://www.dopplerrelay.com/\">Doppler Relay</a> is great!",
      text = "This is an alternative text"
    };

    await request.PostJsonAsync(requestBody);
  }

  static void Main()
  {
    MainAsync().GetAwaiter().GetResult(); // to avoid exceptions being wrapped into AggregateException
  }
}