Skip to content

BrentMcIntosh/MailgunWebhooks

 
 

Repository files navigation

MailgunWebhooks

Mailgun Webhooks WebAPI Endpoints

Build StatusCoverage Status

Validate Mailgun Webhooks Signature in C#

public bool IsValid(WebhookRequest request)
{
    var hmac = new HMACSHA256(Encoding.ASCII.GetBytes(_apiKey));
    var signature = hmac.ComputeHash(Encoding.ASCII.GetBytes(request.Timestamp + request.Token));
    var generatedSignature = BitConverter.ToString(signature).Replace("-", "");
    return generatedSignature.Equals(request.Signature, StringComparison.OrdinalIgnoreCase);
}

Test Web API Webhooks locally directly from Visual Studio and IIS Express

To test Webhooks with online data, you need to expose your local website on internet. Here is a nice clean way to do it with Visual Studio and IIS Express.

  • Open MailgunWebhooks WebAPI solution in Visual Studio.
  • Open %YOUR WORKSPACE%\MailgunWebhooks\.vs\config\applicationhost.config
  • In applicationhost.config look for your Site xml node
  • If 65008 is your port, add the following line
<binding protocol="http" bindingInformation="*:65008:" /><bindings> 
  • Example
<site name="MailgunWebhooks" id="2">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\Workspace\csharp\MailgunWebhooks\MailgunWebhooks" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:65008:" />
        <binding protocol="http" bindingInformation="*:65008:localhost" />
    </bindings>
</site>
  • Open %YOUR WORKSPACE%\MailgunWebhooks\packages.config and replace port 65008 with your port
  • Run your solution from Visual Studio (F5)
  • Open your terminal and navigate to the solution folder to install the npm packages and run start
npm install
npm start
  • The output of "npm start" should be similar with the following:
> mailgun-webhooks@1.0.0 start C:\Workspace\csharp\MailgunWebhooks
> lt --port 65008 --open

your url is: https://elemuzzmps.localtunnel.me
  • The presented url should be opened into your browser

In web.config, change the value of Mailgun key with your Mailgun key

<add key="MailgunKey" value="#########" />

Configure the webhooks on the mailgun website similar to:

About

Mailgun Webhooks WebAPI Endpoints

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.8%
  • Classic ASP 0.2%