Doppler Relay

Quick Examples

PHP Example

See a working PHP example in our GitHub repository

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

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

$data = array(
  'from_name' => 'Your Name',
  'from_email' => 'test@example.com',
  'recipients' => array(
    array(
      'type' => 'to',
      'email' => 'test@example.com',
      '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 requestBody = new
    {
      from_name = "From Name",
      from_email = "from@email.com",
      recipients = new[]
      {
        new
        {
          email = "to@email.com",
          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 client.PostJsonAsync(requestBody);
  }

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