From 32258a5e0211b402666846f684386e78a7ae7e8a Mon Sep 17 00:00:00 2001 From: paritosh baghel Date: Fri, 26 May 2017 15:32:20 -0400 Subject: [PATCH] Manipulate Personalizations USE_CASES.md to demonstrate how to Manipulate Personalizations --- USE_CASES.md | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/USE_CASES.md b/USE_CASES.md index 475f37400..bf1639a7e 100644 --- a/USE_CASES.md +++ b/USE_CASES.md @@ -178,3 +178,62 @@ namespace Example } } ``` +## Use Personalization to manipulate email according to recipient + +```csharp +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using SendGrid; +using SendGrid.Helpers.Mail; + +namespace Example +{ + class Program + { + static void Main(string[] args) + { + Execute().Wait(); + } + + static async Task Execute() + { + var apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY"); + var client = new SendGridClient(apiKey); + var msg = new SendGridMessage(); + msg.SetFrom(new EmailAddress("test@example.com", "Example User")); + msg.SetSubject("Global Subject"); + msg.AddTo(new EmailAddress("test234@example.com")); + msg.AddTo(new EmailAddress("test@example.com"), 0, new Personalization() + { + Subject = "Personalization Subject ", + Tos = new List() + { + new EmailAddress() { Email = "Test12@example.com", Name="test12" }, + new EmailAddress() { Email = "Test13@example.com", Name="Test13" }, + new EmailAddress() { Email = "Test14@example.com", Name="Test14" }, + }, + Bccs = new List() + { + new EmailAddress() { Email = "Test15@example.com", Name="Test15" }, + new EmailAddress() { Email = "Test16@example.com", Name="Test16" }, + new EmailAddress() { Email = "Test17@example.com", Name="Test17" }, + }, + Ccs = new List() + { + new EmailAddress() { Email = "Test25@example.com", Name="Test25" }, + new EmailAddress() { Email = "Test26@example.com", Name="Test26" }, + new EmailAddress() { Email = "Test27@example.com", Name="Test27" }, + } + }); + var mesage = msg.Serialize(); + msg.AddContent(MimeType.Text, "I'm replacing the body tag"); + var response = await client.SendEmailAsync(msg); + Console.WriteLine(response.StatusCode); + Console.WriteLine(response.Headers.ToString()); + Console.WriteLine("\n\nPress any key to exit."); + Console.ReadLine(); + } + } +} +```