SparkPost.DotNetCore
1.0.0
dotnet add package SparkPost.DotNetCore --version 1.0.0
NuGet\Install-Package SparkPost.DotNetCore -Version 1.0.0
<PackageReference Include="SparkPost.DotNetCore" Version="1.0.0" />
paket add SparkPost.DotNetCore --version 1.0.0
#r "nuget: SparkPost.DotNetCore, 1.0.0"
// Install SparkPost.DotNetCore as a Cake Addin #addin nuget:?package=SparkPost.DotNetCore&version=1.0.0 // Install SparkPost.DotNetCore as a Cake Tool #tool nuget:?package=SparkPost.DotNetCore&version=1.0.0
C# Library for SparkPost
A C# package for the SparkPost API. Xamarin.iOS and Xamarin.Android support provided in the Portable Package (PCL Profile7).
Installation
To install via NuGet, run the following command in the Package Manager Console:
PM> Install-Package SparkPost
Alternatively, you can get the latest dll from the releases tab. You can also download this code and compile it yourself.
Usage
Special Note about Async
By default, this library uses .Net 4.5's Async
functionality for better performance (read more here). This requires knowledge and execution
of the async/await behavior in C#. If you're noticing what seems to be weird behavior, or MVC action hangs,
or anything of that nature, just switch your client to Sync
and you'll get the expected (but blocking) behavior.
client.CustomSettings.SendingMode = SendingModes.Sync;
client.Transmissions.Send(transmission); // now this call will be made synchronously
client.CustomSettings.SendingMode = SendingModes.Async;
client.Transmissions.Send(transmission); // now this call will be made asynchronously
Transmissions
To send an email:
var transmission = new Transmission();
transmission.Content.From.Email = "testing@sparkpostbox.com";
transmission.Content.Subject = "Oh hey!";
transmission.Content.Text = "Testing SparkPost - the world\'s most awesomest email service!";
transmission.Content.Html = "<html><body><p>Testing SparkPost - the world\'s most awesomest email service!</p></body></html>";
var recipient = new Recipient
{
Address = new Address { Email = "my@email.com" }
};
transmission.Recipients.Add(recipient);
var client = new Client("<YOUR API KEY>");
client.Transmissions.Send(transmission);
// or client.Transmissions.Send(transmission).Wait();
To send a template email:
var transmission = new Transmission();
transmission.Content.TemplateId = "my-template-id";
transmission.Content.From.Email = "testing@sparkpostbox.com";
transmission.SubstitutionData["first_name"] = "John";
transmission.SubstitutionData["last_name"] = "Doe";
var orders = new List<Order>
{
new Order { OrderId = "1", Total = 101 },
new Order { OrderId = "2", Total = 304 }
};
// you can pass more complicated data, so long as it
// can be parsed easily to JSON
transmission.SubstitutionData["orders"] = orders;
var recipient = new Recipient
{
Address = new Address { Email = "my@email.com" }
};
transmission.Recipients.Add(recipient);
var client = new Client("MY_API_KEY");
client.Transmissions.Send(transmission);
// or client.Transmissions.Send(transmission).Wait();
Sub Accounts
You can use the client to send emails through a sub account by passing the subAccountId
to your client.
client = new Client(YOUR_API_KEY, YOUR_SUB_ACCOUNT_ID);
// now the emails will be processed through your sub account
Suppression List
The suppression list are users who have opted-out of your emails. To retrieve this list:
var client = new Client("MY_API_KEY");
client.Suppressions.List(); // returns a list of
client.Suppressions.List(new { limit = 3 }); // it accepts an anonymous type for filters
client.Suppressions.List(new SuppressionQuery()); // a SuppressionQuery is also allowed for typed help
To add email addresses to the list:
var client = new Client("MY_API_KEY");
var item1 = new Suppression { Email = "testing@testing.com", NonTransactional = true };
var item2 = new Suppression { Email = "testing2@testing.com", Description = "testing" };
client.Suppressions.CreateOrUpdate(new []{ item1, item2 });
To delete email addresses from the list:
var client = new Client("MY_API_KEY");
client.Suppressions.Delete("testing@testing.com");
To retrieve details about an email address on (or not on) the list:
var client = new Client("MY_API_KEY");
client.Suppressions.Retrieve("testing@testing.com");
Setting the API hostname
var client = new Client("MY_API_KEY", "https://api.eu.sparkpost.com");
Contribute
We welcome your contributions! See CONTRIBUTING.md for details on how to help out.
Change Log
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.AspNetCore.StaticFiles (>= 1.1.0)
- Microsoft.CSharp (>= 4.5.0)
- Newtonsoft.Json (>= 11.0.2)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on SparkPost.DotNetCore:
Package | Downloads |
---|---|
SRBCommon
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 285,796 | 11/18/2018 |