Skip to content

Commit 2ff077c

Browse files
stidsborgclaude
andcommitted
Add email sending example to README using CaptureEach
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2760c33 commit 2ff077c

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,33 @@ ConsumeMessages(
260260
## More examples
261261
As an example is worth a thousand lines of documentation - various useful examples are presented in the following section:
262262

263+
### Sending customer emails ([source code](https://github.com/stidsborg/Cleipnir.NET/blob/main/Samples/Cleipnir.Sample.Presentation/C_NewsletterSender/Solution/NewsletterFlow.cs)):
264+
Consider a travel agency which wants to send a promotional email to its customers.
265+
266+
Using `CaptureEach`, the runtime automatically tracks loop progress and removes effects from already completed iterations — keeping storage consumption constant regardless of the number of recipients:
267+
```csharp
268+
public class NewsletterFlow : Flow<MailAndRecipients>
269+
{
270+
public override async Task Run(MailAndRecipients mailAndRecipients)
271+
{
272+
var (recipients, subject, content) = mailAndRecipients;
273+
using var client = new SmtpClient();
274+
await client.ConnectAsync("mail.smtpbucket.com", 8025);
275+
276+
await recipients.CaptureEach(async recipient =>
277+
{
278+
var message = new MimeMessage();
279+
message.To.Add(new MailboxAddress(recipient.Name, recipient.Address));
280+
message.From.Add(new MailboxAddress("The Travel Agency", "offers@thetravelagency.co.uk"));
281+
282+
message.Subject = subject;
283+
message.Body = new TextPart(TextFormat.Html) { Text = content };
284+
await client.SendAsync(message);
285+
});
286+
}
287+
}
288+
```
289+
263290
### Integration-test ([source code](https://github.com/stidsborg/Cleipnir.NET.Sample/blob/48eceea40402590303d5a269aeec9912117c634c/Tests/Cleipnir.Flows.Sample.Tests/RpcOrderFlowTests.cs#L16)):
264291
```csharp
265292
var transactionId = Guid.NewGuid();

0 commit comments

Comments
 (0)