diff --git a/docs/codesnippets/BulkSend.md b/docs/codesnippets/BulkSend.md new file mode 100644 index 0000000..b94b1a5 --- /dev/null +++ b/docs/codesnippets/BulkSend.md @@ -0,0 +1,35 @@ +--- +uid: snippets.bulk-send-email +--- + +# Bulk send an email +Short example of sending email via bulk link. + +```csharp +using Mailtrap; +using Mailtrap.Emails.Requests; +using Mailtrap.Emails.Responses; + +try +{ + var apiToken = ""; + using var mailtrapClientFactory = new MailtrapClientFactory(apiToken); + IMailtrapClient mailtrapClient = mailtrapClientFactory.CreateClient(); + SendEmailRequest request = SendEmailRequest + .Create() + .From("hello@demomailtrap.co", "Mailtrap Test") + .To("world@demomailtrap.co") + .Subject("You are awesome!") + .Category("Integration Test") + .Text("Congrats for sending test email with Mailtrap!"); + SendEmailResponse? response = await mailtrapClient + .Bulk() + .Send(request); +} +catch (Exception ex) +{ + Console.WriteLine("An error occurred while sending email: {0}", ex); +} +``` + +[!INCLUDE [api-token-caution](../includes/api-token-caution.md)] diff --git a/docs/codesnippets/BulkSendFromTemplate.md b/docs/codesnippets/BulkSendFromTemplate.md new file mode 100644 index 0000000..bf16896 --- /dev/null +++ b/docs/codesnippets/BulkSendFromTemplate.md @@ -0,0 +1,41 @@ +--- +uid: snippets.bulk-send-template-email +--- + +# Bulk send from template +Short example of sending email using template via bulk link. + +```csharp +using Mailtrap; +using Mailtrap.Emails.Requests; +using Mailtrap.Emails.Responses; + +try +{ + var apiToken = ""; + using var mailtrapClientFactory = new MailtrapClientFactory(apiToken); + IMailtrapClient mailtrapClient = mailtrapClientFactory.CreateClient(); + SendEmailRequest request = SendEmailRequest + .Create() + .From("hello@demomailtrap.co", "Mailtrap Test") + .To("world@demomailtrap.co") + .Template("") // ID of Email template + .TemplateVariables(new Dictionary // Optional template parameters + { + { "company_info_name", "Test_Company_info_name" }, + { "company_info_address", "Test_Company_info_address" }, + { "company_info_city", "Test_Company_info_city" }, + { "company_info_zip_code", "Test_Company_info_zip_code" }, + { "company_info_country", "Test_Company_info_country" } + }); + SendEmailResponse? response = await mailtrapClient + .Bulk() + .Send(request); +} +catch (Exception ex) +{ + Console.WriteLine("An error occurred while sending email: {0}", ex); +} +``` + +[!INCLUDE [api-token-caution](../includes/api-token-caution.md)] diff --git a/docs/codesnippets/SandboxSendFromTemplate.md b/docs/codesnippets/SandboxSendFromTemplate.md new file mode 100644 index 0000000..a8677bb --- /dev/null +++ b/docs/codesnippets/SandboxSendFromTemplate.md @@ -0,0 +1,42 @@ +--- +uid: snippets.sandbox-send-template-email +--- + +# Sandbox send +Short example of sending email via sandbox link. + +```csharp +using Mailtrap; +using Mailtrap.Emails.Requests; +using Mailtrap.Emails.Responses; + +try +{ + var apiToken = ""; + var sandboxId = ; // ID of sandbox + using var mailtrapClientFactory = new MailtrapClientFactory(apiToken); + IMailtrapClient mailtrapClient = mailtrapClientFactory.CreateClient(); + SendEmailRequest request = SendEmailRequest + .Create() + .From("hello@demomailtrap.co", "Mailtrap Test") + .To("world@demomailtrap.co") + .Template("") // ID of Email template + .TemplateVariables(new Dictionary // Optional template parameters + { + { "company_info_name", "Test_Company_info_name" }, + { "company_info_address", "Test_Company_info_address" }, + { "company_info_city", "Test_Company_info_city" }, + { "company_info_zip_code", "Test_Company_info_zip_code" }, + { "company_info_country", "Test_Company_info_country" } + }); + SendEmailResponse? response = await mailtrapClient + .Test(sandboxId) + .Send(request); +} +catch (Exception ex) +{ + Console.WriteLine("An error occurred while sending email: {0}", ex); +} +``` + +[!INCLUDE [api-token-caution](../includes/api-token-caution.md)] diff --git a/docs/codesnippets/SimpleSend.md b/docs/codesnippets/SimpleSend.md new file mode 100644 index 0000000..160db89 --- /dev/null +++ b/docs/codesnippets/SimpleSend.md @@ -0,0 +1,35 @@ +--- +uid: snippets.simple-send-email +--- + +# Send an email +Short example of sending a simple email. + +```csharp +using Mailtrap; +using Mailtrap.Emails.Requests; +using Mailtrap.Emails.Responses; + +try +{ + var apiToken = ""; + using var mailtrapClientFactory = new MailtrapClientFactory(apiToken); + IMailtrapClient mailtrapClient = mailtrapClientFactory.CreateClient(); + SendEmailRequest request = SendEmailRequest + .Create() + .From("hello@demomailtrap.co", "Mailtrap Test") + .To("world@demomailtrap.co") + .Subject("You are awesome!") + .Category("Integration Test") + .Text("Congrats for sending test email with Mailtrap!"); + SendEmailResponse? response = await mailtrapClient + .Email() + .Send(request); +} +catch (Exception ex) +{ + Console.WriteLine("An error occurred while sending email: {0}", ex); +} +``` + +[!INCLUDE [api-token-caution](../includes/api-token-caution.md)] diff --git a/docs/codesnippets/SimpleSendFromTemplate.md b/docs/codesnippets/SimpleSendFromTemplate.md new file mode 100644 index 0000000..fc686da --- /dev/null +++ b/docs/codesnippets/SimpleSendFromTemplate.md @@ -0,0 +1,40 @@ +--- +uid: snippets.simple-send-template-email +--- + +# Send an email from template +Short example of sending an email from a template. + +```csharp +using Mailtrap; +using Mailtrap.Emails.Requests; +using Mailtrap.Emails.Responses; + +try +{ + var apiToken = ""; + using var mailtrapClientFactory = new MailtrapClientFactory(apiToken); + IMailtrapClient mailtrapClient = mailtrapClientFactory.CreateClient(); + SendEmailRequest request = SendEmailRequest + .Create() + .From("hello@demomailtrap.co", "Mailtrap Test") + .To("world@demomailtrap.co") + .Template("") // ID of Email template + .TemplateVariables(new Dictionary // Optional template parameters + { + { "company_info_name", "Test_Company_info_name" }, + { "company_info_address", "Test_Company_info_address" }, + { "company_info_city", "Test_Company_info_city" }, + { "company_info_zip_code", "Test_Company_info_zip_code" }, + { "company_info_country", "Test_Company_info_country" } + }); + SendEmailResponse? response = await mailtrapClient + .Email() + .Send(request); +} +catch (Exception ex) +{ + Console.WriteLine("An error occurred while sending email: {0}", ex); +} +``` +[!INCLUDE [api-token-caution](../includes/api-token-caution.md)] diff --git a/docs/codesnippets/index.md b/docs/codesnippets/index.md new file mode 100644 index 0000000..1deb46f --- /dev/null +++ b/docs/codesnippets/index.md @@ -0,0 +1,17 @@ +--- +uid: snippets.index +title: Code Snippets +--- +# Code Snippets + +Here you can find short, practical examples of how to use the Mailtrap .NET client. + +Each snippet demonstrates a specific use case, from basic email sending to advanced template usage. + +## Available Snippets + +- [Simple Send Email](xref:snippets.simple-send-email) +- [Send Email from Template](xref:snippets.simple-send-template-email) +- [Bulk Send Email](xref:snippets.bulk-send-email) +- [Bulk Send Template Email](xref:snippets.bulk-send-template-email) +- [Sandbox Template Example](xref:snippets.sandbox-send-template-email) diff --git a/docs/codesnippets/toc.yml b/docs/codesnippets/toc.yml new file mode 100644 index 0000000..a53957a --- /dev/null +++ b/docs/codesnippets/toc.yml @@ -0,0 +1,5 @@ +- uid: snippets.simple-send-email +- uid: snippets.simple-send-template-email +- uid: snippets.bulk-send-email +- uid: snippets.bulk-send-template-email +- uid: snippets.sandbox-send-template-email diff --git a/docs/index.md b/docs/index.md index 4c0315f..cad5446 100644 --- a/docs/index.md +++ b/docs/index.md @@ -21,6 +21,9 @@ Repository with sample projects with different usage scenarios. - [API Reference](xref:Mailtrap) Detailed API reference. +- [Code Snippets](xref:snippets.index) +Code snippets for base send mail operations +