mailgun_csharp 0.9.0

dotnet add package mailgun_csharp --version 0.9.0                
NuGet\Install-Package mailgun_csharp -Version 0.9.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="mailgun_csharp" Version="0.9.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add mailgun_csharp --version 0.9.0                
#r "nuget: mailgun_csharp, 0.9.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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

Nuget

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last updated
0.9.0 205 11/14/2024
0.8.0 18,316 6/19/2023
0.7.0 7,792 7/6/2022
0.7.0-preview2 1,661 6/5/2021
0.7.0-preview1 3,171 5/3/2020
0.6.0 27,857 5/29/2017
0.5.0 9,111 4/20/2016
0.4.0 3,468 6/22/2015
0.3.0 4,767 11/18/2014
0.2.0 2,731 11/16/2014
0.1.0 2,040 11/16/2014

- Multitarget .NET 8 &nestandard to optimize builds
  - Add PDB & Source
  - Bump Newtonsoft to combat vulnerability warnings