diff options
Diffstat (limited to 'SendGrid/Example')
-rw-r--r-- | SendGrid/Example/Program.cs | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/SendGrid/Example/Program.cs b/SendGrid/Example/Program.cs index 753f38c..9b7e359 100644 --- a/SendGrid/Example/Program.cs +++ b/SendGrid/Example/Program.cs @@ -10,6 +10,7 @@ namespace Example {
private static void Main()
{
+ /*
// Test sending email
var to = "example@example.com";
var from = "example@example.com";
@@ -19,6 +20,8 @@ namespace Example ApiKeys();
UnsubscribeGroups();
Suppressions();
+ */
+ GlobalSuppressions();
}
private static void SendAsync(SendGrid.SendGridMessage message)
@@ -95,7 +98,7 @@ namespace Example HttpResponseMessage responseFinal = client.ApiKeys.Get().Result;
Console.WriteLine(responseFinal.StatusCode);
Console.WriteLine(responseFinal.Content.ReadAsStringAsync().Result);
- Console.WriteLine("API Key Deleted, press any key to end");
+ Console.WriteLine("API Key Deleted, press any key to end.");
Console.ReadKey();
}
@@ -136,7 +139,7 @@ namespace Example HttpResponseMessage responseFinal = client.UnsubscribeGroups.Get().Result;
Console.WriteLine(responseFinal.StatusCode);
Console.WriteLine(responseFinal.Content.ReadAsStringAsync().Result);
- Console.WriteLine("Unsubscribe Group Deleted, press any key to end");
+ Console.WriteLine("Unsubscribe Group Deleted, press any key to end.");
Console.ReadKey();
}
@@ -172,7 +175,46 @@ namespace Example HttpResponseMessage responseFinal = client.Suppressions.Get(groupID).Result;
Console.WriteLine(responseFinal.StatusCode);
Console.WriteLine(responseFinal.Content.ReadAsStringAsync().Result);
- Console.WriteLine("Emails removed from Suppression Group" + groupID.ToString() + "Deleted. Press any key to end");
+ Console.WriteLine("Emails removed from Suppression Group" + groupID.ToString() + "Deleted. Press any key to end.");
+ Console.ReadKey();
+ }
+
+ private static void GlobalSuppressions()
+ {
+ String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User);
+ var client = new SendGrid.Client(apiKey);
+
+ // GET SUPPRESSED ADDRESSES FOR A GIVEN GROUP
+ var email = "elmer.thomas+test_global@gmail.com";
+ HttpResponseMessage responseGetUnique = client.GlobalSuppressions.Get(email).Result;
+ Console.WriteLine(responseGetUnique.StatusCode);
+ Console.WriteLine(responseGetUnique.Content.ReadAsStringAsync().Result);
+ Console.WriteLine("Determines if the given email is listed on the Global Suppressions list. Press any key to continue.");
+ Console.ReadKey();
+
+ // ADD EMAILS TO A SUPPRESSION GROUP
+ string[] emails = { "example@example.com", "example2@example.com" };
+ HttpResponseMessage responsePost = client.GlobalSuppressions.Post(emails).Result;
+ var rawString = responsePost.Content.ReadAsStringAsync().Result;
+ dynamic jsonObject = JObject.Parse(rawString);
+ Console.WriteLine(responsePost.StatusCode);
+ Console.WriteLine(responsePost.Content.ReadAsStringAsync().Result);
+ Console.WriteLine("Emails added to Global Suppression Group. Press any key to continue.");
+ Console.ReadKey();
+
+ // DELETE EMAILS FROM A SUPPRESSION GROUP
+ Console.WriteLine("Deleting emails from Global Suppression Group, please wait.");
+ HttpResponseMessage responseDelete1 = client.GlobalSuppressions.Delete("example@example.com").Result;
+ Console.WriteLine(responseDelete1.StatusCode);
+ HttpResponseMessage responseDelete2 = client.GlobalSuppressions.Delete("example2@example.com").Result;
+ Console.WriteLine(responseDelete2.StatusCode);
+ HttpResponseMessage responseFinal = client.GlobalSuppressions.Get("example@example.com").Result;
+ Console.WriteLine(responseFinal.StatusCode);
+ Console.WriteLine(responseFinal.Content.ReadAsStringAsync().Result);
+ HttpResponseMessage responseFinal2 = client.GlobalSuppressions.Get("example2@example.com").Result;
+ Console.WriteLine(responseFinal2.StatusCode);
+ Console.WriteLine(responseFinal2.Content.ReadAsStringAsync().Result);
+ Console.WriteLine("Emails removed from Global Suppression Group. Press any key to end.");
Console.ReadKey();
}
|