mailgun_csharp 0.9.0
dotnet add package mailgun_csharp --version 0.9.0
NuGet\Install-Package mailgun_csharp -Version 0.9.0
<PackageReference Include="mailgun_csharp" Version="0.9.0" />
paket add mailgun_csharp --version 0.9.0
#r "nuget: mailgun_csharp, 0.9.0"
// Install mailgun_csharp as a Cake Addin #addin nuget:?package=mailgun_csharp&version=0.9.0 // Install mailgun_csharp as a Cake Tool #tool nuget:?package=mailgun_csharp&version=0.9.0
Maintained but not developed
This project now is not actively developed. But it works, used for production projects. I'll do my best to fix issues if they appear (they rarely do), and if somebody will contribute some improvements, I'll review them. @leotsarev
mailgun_csharp
A Mailgun API library for C#
Made with inspiration from the Mailgun-php implementation, this library wraps the Mailgun HTTP API for easy use in C# applications.
Download
You can download the source and build it using VS2013, or use Nuget
Install-Package mailgun_csharp
and the ASP.net package (if needed)
Install-Package mailgun_csharp.AspNet.Identity
Basic usage
The current implementation supports creating a MessageService and sending Messages. A Message can be created manually or you can use the recommended MessageBuilder.
var mg = new MessageService(ApiKey);
//var mg = new MessageService(ApiKey,false); //you can specify to use SSL or not, which determines the url API scheme to use
//var mg = new MessageService(ApiKey,false,"api.mailgun.net/v3"); //you can also override the base URL, which defaults to v2
//build a message
var message = new MessageBuilder()
.AddToRecipient(new Recipient
{
Email = "bringking@gmail.com",
DisplayName = "Charlie King"
})
.SetTestMode(true)
.SetSubject("Plain text test")
.SetFromAddress(new Recipient {Email = "bringking@gmail.com", DisplayName = "Mailgun C#"})
.SetTextBody("This is a test")
.GetMessage();
var content = await mg.SendMessageAsync(Domain, message);
content.ShouldNotBeNull();
The current Message object supports all the options listed in the Mailgun documentation here
ASP.net Identity Usage
The new ASP.net Identity system supports the addition of an IIdentityMessageService for sending authorization emails. The Mailgun.AspNet.Identity package has an implementation for use with your Mailgun account. Usage would be something like this-
//wherever you initialize your user manager
_userManager = new UserManager<IdentityUser, string>(store);
//simple usage
_userManager.EmailService = new MailgunMessageService("domain","apiKey");
The above configuration will send plain text emails using the specified domain and apiKey over SSL. For more options, you can pass in an IMailgunMessageServiceOptions object, to specify any custom rackspace configuration options you might have.
//wherever you initialize your user manager
_userManager = new UserManager<IdentityUser, string>(store);
//advanced usage
_userManager.EmailService = new MailgunMessageService(new MailgunMessageServiceOptions
{
ApiKey = "",
Domain = "",
TestMode = true,
Tracking = true,
TrackingClicks = true,
TrackingOpen = true,
UseDkim = true,
DefaultHeaders = new Dictionary<string, string>{{"X-Some-Custom-Header","Custom"}},
DefaultTags = new Collection<string>{"AuthorizationEmails"},
BaseUrlOverride = "api.mailgun.net/v3" //use a different base URL
});
Event retrieval
Message events (logs) can be retrieved from MailGun using
internal async Task<List<string>> GetFailuresAsync()
{
var mg = new MessageService(ApiKey);
//the filter structure is defined here: https://documentation.mailgun.com/en/latest/api-events.html#events
var events = await mg.GetMessageEventsAsync("mg.conveyor.cloud", "event=rejected OR failed&limit=5");
var failures = new List<string>();
//extract email addresses with permanent failures
do
{
failures.AddRange(events.Items.Where(e=>e.Severity=="permanent").Select(e => e.Recipient));
} while ((events = await mg.GetMessageEventsPageAsync(events.Paging.Next)).Items.Count > 0);
return failures;
}
TODO
There is much more to do, but on the plate next are-
- Stored Messages
- Improve events
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 is compatible. 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.Extensions.Http (>= 2.1.0)
- Newtonsoft.Json (>= 13.0.3)
-
net8.0
- Microsoft.Extensions.Http (>= 2.1.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on mailgun_csharp:
Package | Downloads |
---|---|
mailgun_csharp.AspNet.Identity
An IIdentityMessageService implemention using the mailgun_csharp API wrapper |
GitHub repositories
This package is not used by any popular GitHub repositories.
- Multitarget .NET 8 &nestandard to optimize builds
- Add PDB & Source
- Bump Newtonsoft to combat vulnerability warnings