summaryrefslogtreecommitdiffstats
path: root/SendGrid/Example/Example.cs
diff options
context:
space:
mode:
authorMaxim Dubrovkin <dubrovkinmaxim@gmail.com>2016-09-20 20:38:01 +0500
committerMaxim Dubrovkin <dubrovkinmaxim@gmail.com>2016-09-20 20:38:01 +0500
commitd4bee913ec3d94aad50afc60acdd24acff5d4570 (patch)
treea9d000db56b38e702fac08f39f58b16487699969 /SendGrid/Example/Example.cs
parent0e025b2dab4cbb42b914e250df6e147e931c341e (diff)
parent52e690c8d54ad9e7882f0687e7a57c5fb4aedd7f (diff)
downloadsendgrid-csharp-d4bee913ec3d94aad50afc60acdd24acff5d4570.zip
sendgrid-csharp-d4bee913ec3d94aad50afc60acdd24acff5d4570.tar.gz
sendgrid-csharp-d4bee913ec3d94aad50afc60acdd24acff5d4570.tar.bz2
Merge branch 'master' into Code-Simplification
# Conflicts: # SendGrid/Example/Example.cs # SendGrid/SendGrid/Helpers/Mail/Mail.cs # SendGrid/SendGrid/SendGrid.csproj # SendGrid/UnitTest/UnitTest.cs
Diffstat (limited to 'SendGrid/Example/Example.cs')
-rw-r--r--SendGrid/Example/Example.cs73
1 files changed, 73 insertions, 0 deletions
diff --git a/SendGrid/Example/Example.cs b/SendGrid/Example/Example.cs
index 3f2198a..2011a06 100644
--- a/SendGrid/Example/Example.cs
+++ b/SendGrid/Example/Example.cs
@@ -15,11 +15,84 @@ namespace Example
HelloEmail().Wait(); // this will actually send an email
KitchenSink().Wait(); // this will only send an email if you set SandBox Mode to false
+ // v3 Template Example with Mail Helper
+ TemplateWithHelper().Wait();
+
+ // v3 Template Example without Mail Helper
+ TemplateWithoutHelper().Wait();
+
// v3 Web API
ApiKeys().Wait();
}
+ private static async Task TemplateWithHelper()
+ {
+ String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User);
+ dynamic sg = new SendGrid.SendGridAPIClient(apiKey, "https://api.sendgrid.com");
+
+ Email from = new Email("dx@sendgrid.com");
+ String subject = "I'm replacing the subject tag";
+ Email to = new Email("elmer@sendgrid.com");
+ Content content = new Content("text/html", "I'm replacing the <strong>body tag</strong>");
+ Mail mail = new Mail(from, subject, to, content);
+
+ mail.TemplateId = "13b8f94f-bcae-4ec6-b752-70d6cb59f932";
+ mail.Personalization[0].AddSubstitution("-name-", "Example User");
+ mail.Personalization[0].AddSubstitution("-city-", "Denver");
+
+ 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());
+
+ Console.ReadLine();
+
+ }
+
+ private static async Task TemplateWithoutHelper()
+ {
+ String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User);
+ dynamic sg = new SendGrid.SendGridAPIClient(apiKey, "https://api.sendgrid.com");
+
+ string data = @"{
+ 'personalizations': [
+ {
+ 'to': [
+ {
+ 'email': 'elmer@sendgrid.com'
+ }
+ ],
+ 'substitutions': {
+ '-name-': 'Example User',
+ '-city-': 'Denver'
+ },
+ 'subject': 'I\'m replacing the subject tag'
+ }
+ ],
+ 'from': {
+ 'email': 'dx@sendgrid.com'
+ },
+ 'content': [
+ {
+ 'type': 'text/html',
+ 'value': 'I\'m replacing the <strong>body tag</strong>'
+ }
+ ],
+ 'template_id': '13b8f94f-bcae-4ec6-b752-70d6cb59f932'
+ }";
+ //test @example.com
+ Object json = JsonConvert.DeserializeObject<Object>(data);
+ dynamic response = await sg.client.mail.send.post(requestBody: json.ToString());
+
+ Console.WriteLine(response.StatusCode);
+ Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+ Console.WriteLine(response.Headers.ToString());
+
+ Console.ReadLine();
+
+ }
+
private static async Task HelloEmail()
{
String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User);