Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,29 @@ The following is the minimum needed code to send an email with the [/mail/send H
using System;
using SendGrid;
using SendGrid.Helpers.Mail;
using System.Threading.Tasks;

namespace Example
{
internal class Example
{
private static void Main()
{
String apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
Execute.Wait();
}

static async Task Execute()
{
string apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
dynamic sg = new SendGridAPIClient(apiKey);

Email from = new Email("test@example.com");
String subject = "Hello World from the SendGrid CSharp Library!";
string subject = "Hello World from the SendGrid CSharp Library!";
Email to = new Email("test@example.com");
Content content = new Content("text/plain", "Hello, Email!");
Mail mail = new Mail(from, subject, to, content);

dynamic response = sg.client.mail.send.post(requestBody: mail.Get());
dynamic response = await sg.client.mail.send.post(requestBody: mail.Get());
}
}
}
Expand All @@ -89,12 +95,18 @@ The following is the minimum needed code to send an email without the /mail/send
using System;
using SendGrid;
using Newtonsoft.Json; // You can generate your JSON string yourelf or with another library if you prefer
using System.Threading.Tasks;

namespace Example
{
internal class Example
{
private static void Main()
{
Execute.Wait();
}

static async Task Execute()
{
String apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
dynamic sg = new SendGridAPIClient(apiKey);
Expand All @@ -121,7 +133,7 @@ namespace Example
]
}";
Object json = JsonConvert.DeserializeObject<Object>(data);
dynamic response = sg.client.mail.send.post(requestBody: json.ToString());
dynamic response = await sg.client.mail.send.post(requestBody: json.ToString());
}
}
}
Expand All @@ -132,17 +144,23 @@ namespace Example
```csharp
using System;
using SendGrid;
using System.Threading.Tasks;

namespace Example
{
internal class Example
{
private static void Main()
{
Execute.Wait();
}

static async Task Execute()
{
string apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
dynamic sg = new SendGrid.SendGridAPIClient(apiKey);
dynamic response = sg.client.suppression.bounces.get();
}
dynamic response = await sg.client.suppression.bounces.get();
}
}
}
```
Expand All @@ -152,16 +170,22 @@ namespace Example
```csharp
using System;
using SendGrid;
using System.Threading.Tasks;

namespace Example
{
internal class Example
{
private static void Main()
{
string apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
dynamic sg = new SendGrid.SendGridAPIClient(apiKey);
dynamic response = sg.client._("suppression/bounces").get();
Execute.Wait();
}

static async Task Execute()
{
string apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
dynamic sg = new SendGrid.SendGridAPIClient(apiKey);
dynamic response = await sg.client._("suppression/bounces").get();
}
}
}
Expand Down
29 changes: 15 additions & 14 deletions SendGrid/Example/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Web.Script.Serialization;
using SendGrid.Helpers.Mail;
using Newtonsoft.Json;
using System.Threading.Tasks;

namespace Example
{
Expand All @@ -11,15 +12,15 @@ internal class 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");
Expand All @@ -32,7 +33,7 @@ private static void HelloEmail()
Email email = new Email("test2@example.com");
mail.Personalization[0].AddTo(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());
Expand All @@ -42,7 +43,7 @@ private static void HelloEmail()

}

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");
Expand Down Expand Up @@ -229,7 +230,7 @@ private static void KitchenSink()
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());
Expand All @@ -238,15 +239,15 @@ private static void KitchenSink()
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");

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());
Expand All @@ -264,7 +265,7 @@ private static void ApiKeys()
]
}";
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());
Expand All @@ -276,7 +277,7 @@ private static void ApiKeys()
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());
Expand All @@ -289,7 +290,7 @@ private static void ApiKeys()
'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());
Expand All @@ -306,7 +307,7 @@ private static void ApiKeys()
]
}";
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());
Expand All @@ -315,7 +316,7 @@ private static void ApiKeys()
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());

Expand Down
4 changes: 2 additions & 2 deletions SendGrid/SendGrid/SendGrid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SendGrid.CSharp.HTTP.Client, Version=2.0.7.0, Culture=neutral, PublicKeyToken=79219bf4e5ecaaca, processorArchitecture=MSIL">
<HintPath>..\packages\SendGrid.CSharp.HTTP.Client.2.0.7\lib\SendGrid.CSharp.HTTP.Client.dll</HintPath>
<Reference Include="SendGrid.CSharp.HTTP.Client, Version=3.0.0.0, Culture=neutral, PublicKeyToken=79219bf4e5ecaaca, processorArchitecture=MSIL">
<HintPath>..\packages\SendGrid.CSharp.HTTP.Client.3.0.0\lib\SendGrid.CSharp.HTTP.Client.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
2 changes: 1 addition & 1 deletion SendGrid/SendGrid/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<packages>
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
<package id="SendGrid.CSharp.HTTP.Client" version="2.0.7" targetFramework="net452" />
<package id="SendGrid.CSharp.HTTP.Client" version="3.0.0" targetFramework="net452" />
</packages>
Loading