![]() |
VOOZH | about |
dotnet add package PostalApiClient --version 1.3.1
NuGet\Install-Package PostalApiClient -Version 1.3.1
<PackageReference Include="PostalApiClient" Version="1.3.1" />
<PackageVersion Include="PostalApiClient" Version="1.3.1" />Directory.Packages.props
<PackageReference Include="PostalApiClient" />Project file
paket add PostalApiClient --version 1.3.1
#r "nuget: PostalApiClient, 1.3.1"
#:package PostalApiClient@1.3.1
#addin nuget:?package=PostalApiClient&version=1.3.1Install as a Cake Addin
#tool nuget:?package=PostalApiClient&version=1.3.1Install as a Cake Tool
.NET Core API client for postal mail delivery platform
// Read configuration from default section "PostalClient"
builder.Services
.AddPostalApiClient(builder.Configuration);
// or set options from action
builder.Services
.AddPostalApiClient(opt =>
{
opt.Server = "http://mypostal.domain";
opt.ApiKey = "Api-Credential-Key";
});
// or read options from custom configuration section
builder.Services
.AddPostalApiClient(builder.Configuration.GetSection("MyCustomSection"));
// or use combination from custom configuration section
// and action for override some options
builder.Services
.AddPostalApiClient(builder.Configuration.GetSection("MyCustomSection"),
options => {
options.ApiKey = "OtherApiKey";
});
// Can use built-in extension methods for setting HttpClient
// e.g. add request handler or logger or retry policy and etc.
builder.Services
.AddPostalApiClient(builder.Configuration)
.AddLogger<CustomHttpLogger>()
.AddHttpMessageHandler<MyRequestHandler>();
// e.g. in controller
public class PostalController : ControllerBase
{
private readonly PostalClient _postalClient;
public PostalController(PostalClient client)
{
_postalClient = client;
}
// ... actions
}
var result = await _postalClient.GetMessageDeliveriesAsync(messageId);
if (result.IsT1)
{
// error handler
}
// continue code with success result
return result.Match<IActionResult>(
response => Ok(response),
error => BadRequest(error));
All methods always return type OneOf<TSuccess, TError>.
Your can check result.IsT0 for make sure the operation is successful or result.IsT1 that operation error.
Samples
// Send message
var message = new PostalMessage()
{
To = new List<string>
{
"example@example.com",
},
From = "admin@localhost.com",
Subject = "Subject",
PlainBody = "Message body text",
Sender = "Sender email/name",
Tag = "Custom message tag",
ReplyTo = "replyTo@example.com",
Attachments = new List<PostalMessageAttachment>
{
new PostalMessageAttachment()
{
Data = "ContentBse64string",
Name = "Attachment №1",
ContentType = "image/jpeg"
}
},
Headers = new Dictionary<string, string>
{
{"CustomMessageHeader","HeaderValue"}
}
};
var result = await _postalClient.SendMessageAsync(message);
// Get message details
await _postalClient.GetMessageDetailsAsync(messageId, MessageExpansion.Status | MessageExpansion.PlainBody);
All available methods and description see in official docs or samples in Demo project
Create webhook in postal server and add POSTmethod in controller
[HttpPost]
public IActionResult ReceiveWebhook([FromBody] PostalWebhook payload)
{
// ...
// Your webhook handler code
return Ok();
}
PostalWebhook support payload for all events
You're can verification request signature for approval that request was sent by your postal server.
For this need get public key from server DKIM record and set option DkimP
# run on postal server machine
# and copy the p=... part of the TXT record (without the semicolon at the end)
postal default-dkim-record
// Add public key to ApiClient option or in appsettings.json
builder.Services
.AddPostalApiClient(opt =>
{
opt.DkimP = "p= part from drim TXT record";
});
After can use service PostalWebhookVerifier for validate model PostalWebhook signature
[HttpPost]
public async Task<IActionResult> ReceiveWebhook([FromBody] PostalWebhook payload,
[FromServices] PostalWebhookVerifier signatureVerifier)
{
// Check signature
var isVerified = signatureVerifier.IsSignatureVerified(payload, Request.Headers);
// !!IMPORTANT!! not use this method after request body already read.
// This Request.Body usually is empty and verifier return always false
var badUse = await signatureVerifier.IsSignatureVerifiedAsync(Request);
// Your webhook handler code
/// ...
return Ok();
}
You're can install package PostalApiClient.Mvc.Extensions with mvc dependencies and use attribute for request signature automatic validation
[HttpPost]
[PostalSignatureVerify]
public IActionResult ReceiveWebhookWithSignatureVerify([FromBody] PostalWebhook payload)
{
// ...
// Your webhook handler code
return Ok();
}
or write custom middleware for verification with use extension method
// some code before verification
var isVerified = await context.HttpContext.CheckPostalSignatureAsync();
// some code after verification
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 2 NuGet packages that depend on PostalApiClient:
| Package | Downloads |
|---|---|
|
PostalApiClient.Mvc.Extensions
Api client for mail delivery platform Postal. Extenions for MVC |
|
|
RS.EmailSenderPostal
For sending emails using Postal. Builds on PostalApiClient |
This package is not used by any popular GitHub repositories.