Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build/mailtrap-example.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<TargetFrameworks>net9.0</TargetFrameworks>
<UseCommonOutputDirectory>false</UseCommonOutputDirectory>
<OutputType>Exe</OutputType>
<UseCommonOutputDirectory>false</UseCommonOutputDirectory>
<OutputType>Exe</OutputType>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -19,7 +19,7 @@
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<None Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" VersionOverride="9.0.9" />
<PackageReference Include="System.Text.Json" VersionOverride="9.0.9" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk"/>
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" VersionOverride="9.0.9" />
<PackageReference Include="System.Text.Json" VersionOverride="9.0.9" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk"/>
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" VersionOverride="9.0.9" />
<PackageReference Include="System.Text.Json" VersionOverride="9.0.9" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk"/>
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" VersionOverride="9.0.9" />
<PackageReference Include="System.Text.Json" VersionOverride="9.0.9" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk"/>
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" VersionOverride="9.0.9" />
<PackageReference Include="System.Text.Json" VersionOverride="9.0.9" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk"/>
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" VersionOverride="9.0.9" />
<PackageReference Include="System.Text.Json" VersionOverride="9.0.9" />
</ItemGroup>
<ItemGroup>
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk"/>
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" />
<PackageReference Include="System.Text.Json" />
</ItemGroup>
<ItemGroup>
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk"/>
26 changes: 13 additions & 13 deletions examples/Mailtrap.Example.ContactEvents/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@
logger.LogInformation("Contact found with Id {ContactId} and Email {ContactEmail}.", contact.Id, contact.Email);
}

// Get resource for contact events collection
IContactsEventCollectionResource contactsEventsResource = contactsResource.Events(contact.Id);
// Get resource for contact event collection
IContactEventCollectionResource contactEventsResource = contactsResource.Events(contact.Id);

// Create contacts event
var createContactsEventRequest = new CreateContactsEventRequest("MyFirstContactsEvent");
createContactsEventRequest.Params.Add("user_id", 101);
createContactsEventRequest.Params.Add("user_name", "John Smith");
createContactsEventRequest.Params.Add("is_active", true);
createContactsEventRequest.Params.Add("last_seen", null);
ContactsEvent contactsEvent = await contactsEventsResource.Create(createContactsEventRequest);
// Create contact event
var createContactEventRequest = new CreateContactEventRequest("MyFirstContactEvent");
createContactEventRequest.Params.Add("user_id", 101);
createContactEventRequest.Params.Add("user_name", "John Smith");
createContactEventRequest.Params.Add("is_active", true);
createContactEventRequest.Params.Add("last_seen", null);
ContactEvent contactEvent = await contactEventsResource.Create(createContactEventRequest);

logger.LogInformation("Contacts Event created: {Name}", contactsEvent.Name);
logger.LogInformation("ID: {ContactId}", contactsEvent.ContactId);
logger.LogInformation("Created At: {ContactEmail}", contactsEvent.ContactEmail);
foreach (KeyValuePair<string, object?> param in contactsEvent.Params)
logger.LogInformation("Contact Event created: {Name}", contactEvent.Name);
logger.LogInformation("ID: {ContactId}", contactEvent.ContactId);
logger.LogInformation("Email: {ContactEmail}", contactEvent.ContactEmail);
foreach (KeyValuePair<string, object?> param in contactEvent.Params)
{
logger.LogInformation("Param: {ParamKey} = {ParamValue}", param.Key, param.Value);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http"/>
</ItemGroup>
<ItemGroup>
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk"/>
44 changes: 22 additions & 22 deletions examples/Mailtrap.Example.ContactFields/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,42 +30,42 @@
IContactCollectionResource contactsResource = accountResource.Contacts();

// Get resource for contact fields collection
IContactsFieldCollectionResource contactsFieldsResource = contactsResource.Fields();
IContactFieldCollectionResource contactFieldsResource = contactsResource.Fields();

// Get all contacts fields for account
IList<ContactsField> contactsFields = await contactsFieldsResource.GetAll();
// Get all contact fields for account
IList<ContactField> contactFields = await contactFieldsResource.GetAll();

ContactsField? contactsField = contactsFields.Count > 0 ? contactsFields[0] : null;
ContactField? contactField = contactFields.Count > 0 ? contactFields[0] : null;

if (contactsField is null)
if (contactField is null)
{
logger.LogWarning("No contacts field found. Creating.");
logger.LogWarning("No contact field found. Creating.");

// Create contacts field
var createContactsFieldRequest = new CreateContactsFieldRequest("MyFirstContactsField", "TestMergeTag", ContactsFieldDataType.Text);
contactsField = await contactsFieldsResource.Create(createContactsFieldRequest);
// Create contact field
var createContactFieldRequest = new CreateContactFieldRequest("MyFirstContactField", "TestMergeTag", ContactFieldDataType.Text);
contactField = await contactFieldsResource.Create(createContactFieldRequest);
}
else
{
logger.LogInformation("Contacts Field {Name} found.", contactsField.Name);
logger.LogInformation("Contact Field {Name} found.", contactField.Name);
}

// Get resource for specific contacts field
IContactsFieldResource contactsFieldResource = contactsResource.Field(contactsField.Id);
// Get resource for specific contact field
IContactFieldResource contactFieldResource = contactsResource.Field(contactField.Id);

// Get details
ContactsField contactsFieldDetails = await contactsFieldResource.GetDetails();
logger.LogInformation("Contacts Field from resource: {Name}", contactsFieldDetails.Name);
ContactField contactFieldDetails = await contactFieldResource.GetDetails();
logger.LogInformation("Contact Field from resource: {Name}", contactFieldDetails.Name);

// Update contacts field details
var updateContactsFieldRequest = new UpdateContactsFieldRequest("UpdatedContactsField", "UpdatedMergeTag");
ContactsField updateContactsFieldResponse = await contactsFieldResource.Update(updateContactsFieldRequest);
logger.LogInformation("Updated Contacts Field: Name={Name}, Id={Id}", updateContactsFieldResponse.Name, updateContactsFieldResponse.Id);

// Delete contacts Field
// Beware that contacts Field resource becomes invalid after deletion and should not be used anymore
await contactsFieldResource.Delete();
logger.LogInformation("Contacts Field Deleted.");
var updateContactFieldRequest = new UpdateContactFieldRequest("UpdatedContactField", "UpdatedMergeTag");
ContactField updateContactFieldResponse = await contactFieldResource.Update(updateContactFieldRequest);
logger.LogInformation("Updated Contact Field: Name={Name}, Id={Id}", updateContactFieldResponse.Name, updateContactFieldResponse.Id);

// Delete contact Field
// Beware that contact Field resource becomes invalid after deletion and should not be used anymore
await contactFieldResource.Delete();
logger.LogInformation("Contact Field Deleted.");
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" />
<PackageReference Include="System.Text.Json" />
</ItemGroup>
<ItemGroup>
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk"/>
26 changes: 15 additions & 11 deletions examples/Mailtrap.Example.ContactImports/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
// Get resource for contacts collection
IContactCollectionResource contactsResource = accountResource.Contacts();

//Get resource for contact imports collection
IContactsImportCollectionResource contactsImportsResource = contactsResource.Imports();
//Get resource for contact import collection
IContactImportCollectionResource contactImportsResource = contactsResource.Imports();

// Prepare list of contacts to import
var contactImportList = new List<ContactImportRequest>
Expand All @@ -42,21 +42,25 @@
new("charlie@mailtrap.io"),
};

// Create contacts import request
var importRequest = new ContactsImportRequest(contactImportList);
// Create contact import request
var importRequest = new CreateContactImportRequest(contactImportList);

// Import contacts in bulk
ContactsImport importResponse = await contactsImportsResource.Create(importRequest);
logger.LogInformation("Created contact import: {Import}", importResponse);
ContactImport importResponse = await contactImportsResource.Create(importRequest);
logger.LogInformation("Created contact import, Id: {ImportId}", importResponse.Id);

// Get resource for specific contact import
IContactsImportResource contactsImportResource = contactsResource.Import(importResponse.Id);
IContactImportResource contactImportResource = contactsResource.Import(importResponse.Id);

// Get details of specific contact import
ContactsImport contactsImportDetails = await contactsImportResource.GetDetails();
logger.LogInformation("Contacts Import Details: {Details}", contactsImportDetails);

if (contactsImportDetails.Status == ContactsImportStatus.Failed)
ContactImport contactImportDetails = await contactImportResource.GetDetails();
logger.LogInformation("Contact Import Details: {Id}", contactImportDetails.Id);
logger.LogInformation("Contact Import Details: {Status}", contactImportDetails.Status);
logger.LogInformation("Contact Import Details: {CreatedContactsCount}", contactImportDetails.CreatedContactsCount);
logger.LogInformation("Contact Import Details: {UpdatedContactsCount}", contactImportDetails.UpdatedContactsCount);
logger.LogInformation("Contact Import Details: {ContactsOverLimitCount}", contactImportDetails.ContactsOverLimitCount);

if (contactImportDetails.Status == ContactImportStatus.Failed)
{
logger.LogWarning("Import failed!");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" />
<PackageReference Include="System.Text.Json" />
</ItemGroup>
<ItemGroup>
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk"/>
49 changes: 25 additions & 24 deletions examples/Mailtrap.Example.ContactLists/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,44 @@
// Get resource for contacts collection
IContactCollectionResource contactsResource = accountResource.Contacts();

// Get resource for contacts list collection
IContactsListCollectionResource contactsListsResource = contactsResource.Lists();
// Get resource for contact lists collection
IContactListCollectionResource contactListsResource = contactsResource.Lists();

// Get all contacts lists for account
IList<ContactsList> contactsLists = await contactsListsResource.GetAll();
// Get all contact lists for account
IList<ContactList> contactLists = await contactListsResource.GetAll();

ContactsList? contactsList = contactsLists.Count > 0 ? contactsLists[0] : null;
ContactList? contactList = contactLists.Count > 0 ? contactLists[0] : null;

if (contactsList is null)
if (contactList is null)
{
logger.LogWarning("No contacts list found. Creating.");

// Create contacts list
var createContactsListRequest = new ContactsListRequest("MyFirstContactsList");
contactsList = await contactsListsResource.Create(createContactsListRequest);
// Create contact list
var createContactsListRequest = new ContactListRequest("MyFirstContactList");
contactList = await contactListsResource.Create(createContactsListRequest);
}
else
{
logger.LogInformation("Contacts List {Name} found.", contactsList.Name);
logger.LogInformation("Contact List {Name} found.", contactList.Name);
}

// Get resource for specific contacts list
IContactsListResource contactsListResource = contactsResource.List(contactsList.Id);
// Get resource for specific contact list
IContactListResource contactListResource = contactsResource.List(contactList.Id);

// Get details
ContactsList contactsListResponse = await contactsListResource.GetDetails();
logger.LogInformation("Contacts List from resource: {Name}", contactsListResponse.Name);

// Update contacts list details
var updateContactsListRequest = new ContactsListRequest("updatedContactsList");
ContactsList updateContactsListResponse = await contactsListResource.Update(updateContactsListRequest);
logger.LogInformation("Updated Contacts List: Name={Name}, Id={Id}", updateContactsListResponse.Name, updateContactsListResponse.Id);

// Delete contacts List
// Beware that contacts list resource becomes invalid after deletion and should not be used anymore
await contactsListResource.Delete();
logger.LogInformation("Contacts List Deleted.");
ContactList contactListResponse = await contactListResource.GetDetails();
logger.LogInformation("Contact List Name from resource: {Name}", contactListResponse.Name);
logger.LogInformation("Contact List Id from resource: {Id}", contactListResponse.Id);

// Update contact list details
var updateContactListRequest = new ContactListRequest("updatedContactList");
ContactList updateContactListResponse = await contactListResource.Update(updateContactListRequest);
logger.LogInformation("Updated Contact List: Name={Name}, Id={Id}", updateContactListResponse.Name, updateContactListResponse.Id);

// Delete contact List
// Beware that contact list resource becomes invalid after deletion and should not be used anymore
await contactListResource.Delete();
logger.LogInformation("Contact List Deleted.");
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>

<PackageReference Include="Microsoft.Extensions.Http" VersionOverride="9.0.9" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" />
<PackageReference Include="System.Text.Json" VersionOverride="9.0.9" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" VersionOverride="9.0.9" />
<PackageReference Include="System.Text.Json" VersionOverride="9.0.9" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk"/>
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>

<PackageReference Include="Microsoft.Extensions.Http" VersionOverride="9.0.9" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" />
<PackageReference Include="System.Text.Json" VersionOverride="9.0.9" />
</ItemGroup>

<ItemGroup>
<None Remove="appsettings.json"/>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" VersionOverride="9.0.9" />
<PackageReference Include="System.Text.Json" VersionOverride="9.0.9" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk"/>
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" VersionOverride="9.0.9" />
<PackageReference Include="System.Text.Json" VersionOverride="9.0.9" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk"/>
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" VersionOverride="9.0.9" />
<PackageReference Include="System.Text.Json" VersionOverride="9.0.9" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk"/>
Loading