Skip to content

Commit 32258a5

Browse files
Manipulate Personalizations
USE_CASES.md to demonstrate how to Manipulate Personalizations
1 parent c3b6431 commit 32258a5

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

USE_CASES.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,62 @@ namespace Example
178178
}
179179
}
180180
```
181+
## Use Personalization to manipulate email according to recipient
182+
183+
```csharp
184+
using System;
185+
using System.Collections.Generic;
186+
using System.Threading.Tasks;
187+
using SendGrid;
188+
using SendGrid.Helpers.Mail;
189+
190+
namespace Example
191+
{
192+
class Program
193+
{
194+
static void Main(string[] args)
195+
{
196+
Execute().Wait();
197+
}
198+
199+
static async Task Execute()
200+
{
201+
var apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY");
202+
var client = new SendGridClient(apiKey);
203+
var msg = new SendGridMessage();
204+
msg.SetFrom(new EmailAddress("[email protected]", "Example User"));
205+
msg.SetSubject("Global Subject");
206+
msg.AddTo(new EmailAddress("[email protected]"));
207+
msg.AddTo(new EmailAddress("[email protected]"), 0, new Personalization()
208+
{
209+
Subject = "Personalization Subject ",
210+
Tos = new List<EmailAddress>()
211+
{
212+
new EmailAddress() { Email = "[email protected]", Name="test12" },
213+
new EmailAddress() { Email = "[email protected]", Name="Test13" },
214+
new EmailAddress() { Email = "[email protected]", Name="Test14" },
215+
},
216+
Bccs = new List<EmailAddress>()
217+
{
218+
new EmailAddress() { Email = "[email protected]", Name="Test15" },
219+
new EmailAddress() { Email = "[email protected]", Name="Test16" },
220+
new EmailAddress() { Email = "[email protected]", Name="Test17" },
221+
},
222+
Ccs = new List<EmailAddress>()
223+
{
224+
new EmailAddress() { Email = "[email protected]", Name="Test25" },
225+
new EmailAddress() { Email = "[email protected]", Name="Test26" },
226+
new EmailAddress() { Email = "[email protected]", Name="Test27" },
227+
}
228+
});
229+
var mesage = msg.Serialize();
230+
msg.AddContent(MimeType.Text, "I'm replacing the <strong>body tag</strong>");
231+
var response = await client.SendEmailAsync(msg);
232+
Console.WriteLine(response.StatusCode);
233+
Console.WriteLine(response.Headers.ToString());
234+
Console.WriteLine("\n\nPress any key to exit.");
235+
Console.ReadLine();
236+
}
237+
}
238+
}
239+
```

0 commit comments

Comments
 (0)