summaryrefslogtreecommitdiffstats
path: root/SendGrid/Example
diff options
context:
space:
mode:
Diffstat (limited to 'SendGrid/Example')
-rw-r--r--SendGrid/Example/Example.cs36
-rw-r--r--SendGrid/Example/Properties/AssemblyInfo.cs4
2 files changed, 24 insertions, 16 deletions
diff --git a/SendGrid/Example/Example.cs b/SendGrid/Example/Example.cs
index 133160f..75c3b47 100644
--- a/SendGrid/Example/Example.cs
+++ b/SendGrid/Example/Example.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Web.Script.Serialization;
using SendGrid.Helpers.Mail;
using Newtonsoft.Json;
+using System.Threading.Tasks;
namespace Example
{
@@ -11,15 +12,15 @@ namespace Example
private static void Main()
{
// v3 Mail Helper
- HelloEmail(); // this will actually send an email
- KitchenSink(); // this will only send an email if you set SandBox Mode to false
+ HelloEmail().Wait(); // this will actually send an email
+ KitchenSink().Wait(); // this will only send an email if you set SandBox Mode to false
// v3 Web API
- ApiKeys();
+ ApiKeys().Wait();
}
- private static void HelloEmail()
+ private static async Task HelloEmail()
{
String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User);
dynamic sg = new SendGrid.SendGridAPIClient(apiKey, "https://api.sendgrid.com");
@@ -32,7 +33,14 @@ namespace Example
Email email = new Email("test2@example.com");
mail.Personalization[0].AddTo(email);
- dynamic response = sg.client.mail.send.post(requestBody: mail.Get());
+ // If you want to use a transactional [template](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html),
+ // the following code will replace the above subject and content. The sample code assumes you have defined
+ // substitution variables [KEY_1] and [KEY_2], to be replaced by VALUE_1 and VALUE_2 respectively, in your template.
+ //mail.TemplateId = "TEMPLATE_ID";
+ //mail.Personalization[0].AddSubstitution("[KEY_1]", "VALUE_1");
+ //mail.Personalization[0].AddSubstitution("[KEY_2]", "VALUE_2");
+
+ dynamic response = await sg.client.mail.send.post(requestBody: mail.Get());
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers.ToString());
@@ -42,7 +50,7 @@ namespace Example
}
- private static void KitchenSink()
+ private static async Task KitchenSink()
{
String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User);
dynamic sg = new SendGrid.SendGridAPIClient(apiKey, "https://api.sendgrid.com");
@@ -229,7 +237,7 @@ namespace Example
email.Address = "test@example.com";
mail.ReplyTo = email;
- dynamic response = sg.client.mail.send.post(requestBody: mail.Get());
+ dynamic response = await sg.client.mail.send.post(requestBody: mail.Get());
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers.ToString());
@@ -238,7 +246,7 @@ namespace Example
Console.ReadLine();
}
- private static void ApiKeys()
+ private static async Task ApiKeys()
{
String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User);
dynamic sg = new SendGrid.SendGridAPIClient(apiKey, "https://api.sendgrid.com");
@@ -246,7 +254,7 @@ namespace Example
string queryParams = @"{
'limit': 100
}";
- dynamic response = sg.client.api_keys.get(queryParams: queryParams);
+ dynamic response = await sg.client.api_keys.get(queryParams: queryParams);
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers.ToString());
@@ -264,7 +272,7 @@ namespace Example
]
}";
Object json = JsonConvert.DeserializeObject<Object>(requestBody);
- response = sg.client.api_keys.post(requestBody: json.ToString());
+ response = await sg.client.api_keys.post(requestBody: json.ToString());
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers.ToString());
@@ -276,7 +284,7 @@ namespace Example
Console.ReadLine();
// GET Single
- response = sg.client.api_keys._(api_key_id).get();
+ response = await sg.client.api_keys._(api_key_id).get();
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers.ToString());
@@ -289,7 +297,7 @@ namespace Example
'name': 'A New Hope'
}";
json = JsonConvert.DeserializeObject<Object>(requestBody);
- response = sg.client.api_keys._(api_key_id).patch(requestBody: json.ToString());
+ response = await sg.client.api_keys._(api_key_id).patch(requestBody: json.ToString());
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers.ToString());
@@ -306,7 +314,7 @@ namespace Example
]
}";
json = JsonConvert.DeserializeObject<Object>(requestBody);
- response = sg.client.api_keys._(api_key_id).put(requestBody: json.ToString());
+ response = await sg.client.api_keys._(api_key_id).put(requestBody: json.ToString());
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers.ToString());
@@ -315,7 +323,7 @@ namespace Example
Console.ReadLine();
// DELETE
- response = sg.client.api_keys._(api_key_id).delete();
+ response = await sg.client.api_keys._(api_key_id).delete();
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Headers.ToString());
diff --git a/SendGrid/Example/Properties/AssemblyInfo.cs b/SendGrid/Example/Properties/AssemblyInfo.cs
index 6c1a8c0..dd5cc3f 100644
--- a/SendGrid/Example/Properties/AssemblyInfo.cs
+++ b/SendGrid/Example/Properties/AssemblyInfo.cs
@@ -35,5 +35,5 @@ using System.Runtime.InteropServices;
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("7.1.1")]
-[assembly: AssemblyFileVersion("7.1.1")] \ No newline at end of file
+[assembly: AssemblyVersion("8.0.1")]
+[assembly: AssemblyFileVersion("8.0.1")]