-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathvalidateRecipient.cs
37 lines (32 loc) · 1.35 KB
/
validateRecipient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// API call example. See https://www.sparkpost.com/docs/recipient-validation/integration-guide/
using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
namespace recipient_validation
{
class Program
{
// set to api.eu.sparkpost.com for EU accounts
const string url = "https://api.sparkpost.com/api/v1/recipient-validation/single/";
static readonly HttpClient client = new HttpClient();
// baed on https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?redirectedfrom=MSDN&view=netframework-4.8
static async Task Main(string[] args)
{
string recipient = "[email protected]";
string apiKey = Environment.GetEnvironmentVariable("SPARKPOST_API_KEY"); // API key from environment variable. Should have Recipient Validation rights
try
{
client.DefaultRequestHeaders.Add("Authorization", apiKey);
client.DefaultRequestHeaders.Add("Accept", "application/json");
var result = await client.GetStringAsync(url + recipient);
Console.WriteLine(result);
}
catch (HttpRequestException e)
{
Console.WriteLine("\nException Caught!");
Console.WriteLine("Message :{0} ", e.Message);
}
}
}
}