diff options
author | Elmer Thomas <elmer@thinkingserious.com> | 2016-08-24 10:44:59 -0700 |
---|---|---|
committer | Maxim Dubrovkin <maximdubrovkin@Maxims-MBP.Dlink> | 2016-09-20 20:13:45 +0500 |
commit | 17fc6513913afaac248f78944ca30b4e8df44542 (patch) | |
tree | 5b87c9989d2bd38049ea0ace87966c47c9c05e14 | |
parent | 27840f11facfa60204bd4f71daf82f100c9bf3f4 (diff) | |
download | sendgrid-csharp-17fc6513913afaac248f78944ca30b4e8df44542.zip sendgrid-csharp-17fc6513913afaac248f78944ca30b4e8df44542.tar.gz sendgrid-csharp-17fc6513913afaac248f78944ca30b4e8df44542.tar.bz2 |
Add TOC for README, Add USE_CASES.md
-rw-r--r-- | README.md | 26 | ||||
-rw-r--r-- | USE_CASES.md | 135 |
2 files changed, 161 insertions, 0 deletions
@@ -10,6 +10,20 @@ Please browse the rest of this README for further detail. We appreciate your continued support, thank you! +# Table of Contents + +* [Installation](#installation) +* [Quick Start](#quick_start) +* [Usage](#usage) +* [Use Cases](#use_cases) +* [Announcements](#announcements) +* [Roadmap](#roadmap) +* [How to Contribute](#contribute) +* [Troubleshooting](#troubleshooting) +* [About](#about) + + +<a name="installation"></a> # Installation ## Prerequisites @@ -45,6 +59,7 @@ using SendGrid.Helpers.Mail; // Include if you want to use the Mail Helper - [SendGrid.CSharp.HTTP.Client](https://github.com/sendgrid/csharp-http-client) - [Newtonsoft.Json](http://www.newtonsoft.com/json) +<a name="quick_start"></a> # Quick Start ## Hello Email @@ -191,6 +206,7 @@ namespace Example } ``` +<a name="usage"></a> # Usage - [SendGrid Docs](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html) @@ -199,14 +215,22 @@ namespace Example - [How-to: Migration from v2 to v3](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/how_to_migrate_from_v2_to_v3_mail_send.html) - [v3 Web API Mail Send Helper](https://github.com/sendgrid/sendgrid-csharp/tree/master/SendGrid/SendGrid/Helpers/Mail) +<a name="use_cases"> +# Use Cases + +[Examples of common API use cases](https://github.com/sendgrid/sendgrid-csharp/blob/master/USE_CASES.md), such as how to send an email with a transactional template. + +<a name="announcements"></a> # Announcements All updates to this library is documented in our [CHANGELOG](https://github.com/sendgrid/sendgrid-csharp/blob/master/CHANGELOG.md) and [releases](https://github.com/sendgrid/sendgrid-csharp/releases). +<a name="roadmap"></a> # Roadmap If you are interested in the future direction of this project, please take a look at our open [issues](https://github.com/sendgrid/sendgrid-csharp/issues) and [pull requests](https://github.com/sendgrid/sendgrid-csharp/pulls). We would love to hear your feedback. +<a name="contribute"></a> # How to Contribute We encourage contribution to our library (you might even score some nifty swag), please see our [CONTRIBUTING](https://github.com/sendgrid/sendgrid-csharp/tree/master/CONTRIBUTING.md) guide for details. @@ -218,10 +242,12 @@ Quick links: - [Sign the CLA to Create a Pull Request](https://github.com/sendgrid/sendgrid-csharp/tree/master/CONTRIBUTING.md#cla) - [Improvements to the Codebase](https://github.com/sendgrid/sendgrid-csharp/tree/master/CONTRIBUTING.md#improvements_to_the_codebase) +<a name="troubleshooting"></a> # Troubleshooting Please see our [troubleshooting guide](https://github.com/sendgrid/sendgrid-csharp/blob/master/TROUBLESHOOTING.md) for common library issues. +<a name="about"></a> # About sendgrid-csharp is guided and supported by the SendGrid [Developer Experience Team](mailto:dx@sendgrid.com). diff --git a/USE_CASES.md b/USE_CASES.md new file mode 100644 index 0000000..0b6f50c --- /dev/null +++ b/USE_CASES.md @@ -0,0 +1,135 @@ +This documentation provides examples for specific use cases. Please [open an issue](https://github.com/sendgrid/sendgrid-sharp/issues) or make a pull request for any use cases you would like us to document here. Thank you! + +# Table of Contents + +* [Transactional Templates](#transactional_templates) + +<a name="transactional_templates"></a> +# Transactional Templates + +For this example, we assume you have created a [transactional template](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). Following is the template content we used for testing. + +Template ID (replace with your own): + +```text +13b8f94f-bcae-4ec6-b752-70d6cb59f932 +``` + +Email Subject: + +```text +<%subject%> +``` + +Template Body: + +```html +<html> +<head> + <title></title> +</head> +<body> +Hello -name-, +<br /><br/> +I'm glad you are trying out the template feature! +<br /><br/> +<%body%> +<br /><br/> +I hope you are having a great day in -city- :) +<br /><br/> +</body> +</html> +``` + +## With Mail Helper Class + +```charp +using System; +using SendGrid; +using SendGrid.Helpers.Mail; +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); + + Email from = new Email("test@example.com"); + String subject = "I'm replacing the subject tag"; + Email to = new Email("test@example.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()); + } + } +} +``` + +## Without Mail Helper Class + +```csharp +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); + + string data = @"{ + 'personalizations': [ + { + 'to': [ + { + 'email': 'test@example.com' + } + ], + 'substitutions': { + '-name-': 'Example User', + '-city-': 'Denver' + }, + 'subject': 'I\'m replacing the subject tag' + } + ], + 'from': { + 'email': 'test@example.com' + }, + 'content': [ + { + 'type': 'text/html', + 'value': 'I\'m replacing the <strong>body tag</strong>' + } + ], + 'template_id': '13b8f94f-bcae-4ec6-b752-70d6cb59f932' + }"; + Object json = JsonConvert.DeserializeObject<Object>(data); + dynamic response = await sg.client.mail.send.post(requestBody: json.ToString()); + } + } +} +```
\ No newline at end of file |