diff options
author | Elmer Thomas <elmer@thinkingserious.com> | 2016-06-01 10:50:02 -0700 |
---|---|---|
committer | Elmer Thomas <elmer@thinkingserious.com> | 2016-06-01 10:50:02 -0700 |
commit | 4cde4e7ee0329c179fa8745655a602521f1c2dd8 (patch) | |
tree | b1cf20f427ef68c644f6c0cd724b72440d53728d /examples/mail/mail.cs | |
parent | 5e5c58f4245647611eb33e03d26d032b7ec2b26e (diff) | |
download | sendgrid-csharp-4cde4e7ee0329c179fa8745655a602521f1c2dd8.zip sendgrid-csharp-4cde4e7ee0329c179fa8745655a602521f1c2dd8.tar.gz sendgrid-csharp-4cde4e7ee0329c179fa8745655a602521f1c2dd8.tar.bz2 |
Added examples for v3 Web API endpoints
Diffstat (limited to 'examples/mail/mail.cs')
-rw-r--r-- | examples/mail/mail.cs | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/examples/mail/mail.cs b/examples/mail/mail.cs new file mode 100644 index 0000000..7e329d0 --- /dev/null +++ b/examples/mail/mail.cs @@ -0,0 +1,179 @@ +using System; +using SendGrid.Helpers.Mail; +using System.Collections.Generic; +using System.Net; + +string _apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); +dynamic sg = new SendGrid.SendGridAPIClient(_apiKey); + +################################################## +# Create a batch ID # +# POST /mail/batch # + +dynamic response = sg.client.mail.batch.post(); +Console.WriteLine(response.StatusCode); +Console.WriteLine(response.ResponseBody.ReadAsStringAsync().Result); +Console.WriteLine(response.ResponseHeaders.ToString()); + +################################################## +# Validate batch ID # +# GET /mail/batch/{batch_id} # + +var batch_id = "test_url_param"; +dynamic response = sg.client.mail.batch._(batch_id).get(); +Console.WriteLine(response.StatusCode); +Console.WriteLine(response.ResponseBody.ReadAsStringAsync().Result); +Console.WriteLine(response.ResponseHeaders.ToString()); + +################################################## +# v3 Mail Send Beta # +# POST /mail/send/beta # + +string data = @"{ + 'asm': { + 'group_id': 1, + 'groups_to_display': [ + 1, + 2, + 3 + ] + }, + 'attachments': [ + { + 'content': '[BASE64 encoded content block here]', + 'content_id': 'ii_139db99fdb5c3704', + 'disposition': 'inline', + 'filename': 'file1.jpg', + 'name': 'file1', + 'type': 'jpg' + } + ], + 'batch_id': '[YOUR BATCH ID GOES HERE]', + 'categories': [ + 'category1', + 'category2' + ], + 'content': [ + { + 'type': 'text/html', + 'value': '<html><p>Hello, world!</p><img src='cid:ii_139db99fdb5c3704'></img></html>' + } + ], + 'custom_args': { + 'New Argument 1': 'New Value 1', + 'activationAttempt': '1', + 'customerAccountNumber': '[CUSTOMER ACCOUNT NUMBER GOES HERE]' + }, + 'from': { + 'email': 'sam.smith@example.com', + 'name': 'Sam Smith' + }, + 'headers': {}, + 'ip_pool_name': '[YOUR POOL NAME GOES HERE]', + 'mail_settings': { + 'bcc': { + 'email': 'ben.doe@example.com', + 'enable': true + }, + 'bypass_list_management': { + 'enable': true + }, + 'footer': { + 'enable': true, + 'html': '<p>Thanks</br>The SendGrid Team</p>', + 'text': 'Thanks,/n The SendGrid Team' + }, + 'sandbox_mode': { + 'enable': false + }, + 'spam_check': { + 'enable': true, + 'post_to_url': 'http://example.com/compliance', + 'threshold': 3 + } + }, + 'personalizations': [ + { + 'bcc': [ + { + 'email': 'sam.doe@example.com', + 'name': 'Sam Doe' + } + ], + 'cc': [ + { + 'email': 'jane.doe@example.com', + 'name': 'Jane Doe' + } + ], + 'custom_args': { + 'New Argument 1': 'New Value 1', + 'activationAttempt': '1', + 'customerAccountNumber': '[CUSTOMER ACCOUNT NUMBER GOES HERE]' + }, + 'headers': { + 'X-Accept-Language': 'en', + 'X-Mailer': 'MyApp' + }, + 'send_at': 1409348513, + 'subject': 'Hello, World!', + 'substitutions': { + 'sub': { + '%name%': [ + 'John', + 'Jane', + 'Sam' + ] + } + }, + 'to': [ + { + 'email': 'john.doe@example.com', + 'name': 'John Doe' + } + ] + } + ], + 'reply_to': { + 'email': 'sam.smith@example.com', + 'name': 'Sam Smith' + }, + 'sections': { + 'section': { + ':sectionName1': 'section 1 text', + ':sectionName2': 'section 2 text' + } + }, + 'send_at': 1409348513, + 'subject': 'Hello, World!', + 'template_id': '[YOUR TEMPLATE ID GOES HERE]', + 'tracking_settings': { + 'click_tracking': { + 'enable': true, + 'enable_text': true + }, + 'ganalytics': { + 'enable': true, + 'utm_campaign': '[NAME OF YOUR REFERRER SOURCE]', + 'utm_content': '[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]', + 'utm_medium': '[NAME OF YOUR MARKETING MEDIUM e.g. email]', + 'utm_name': '[NAME OF YOUR CAMPAIGN]', + 'utm_term': '[IDENTIFY PAID KEYWORDS HERE]' + }, + 'open_tracking': { + 'enable': true, + 'substitution_tag': '%opentrack' + }, + 'subscription_tracking': { + 'enable': true, + 'html': 'If you would like to unsubscribe and stop receiving these emails <% clickhere %>.', + 'substitution_tag': '<%click here%>', + 'text': 'If you would like to unsubscribe and stop receiveing these emails <% click here %>.' + } + } +}"; +dynamic response = sg.client.mail.send.beta.post(requestBody: data); +Console.WriteLine(response.StatusCode); +Console.WriteLine(response.ResponseBody.ReadAsStringAsync().Result); +Console.WriteLine(response.ResponseHeaders.ToString()); + |