2

This question is going to seem rather vague, but that is possibly because I do not really understand what I need to do or how to go about it.

Mailgun has a way for users to get the response of emails sent using it's API and Webhooks.

help.mailgun.com : How do webhooks work?

I really do not understand how to get this to work.

I have a hosted ISP that we are sending emails from.

Obviously, I do not want to try to get the response immediately after sending the message from the webform because the responses could come days later.

Would this need to be a server installed component? If so, would I need to install a component via the ISP's Control Panel or would I be able to write something that would install it when run from Visual Studio?

There could be another name for what I'm doing. As it is now, I can't seem to find any results.

This website does NOT use MVC. Maybe one day.

1 Answers1

2

According to the documentation, there are two ways to get feedback from Mailgun:
https://documentation.mailgun.com/user_manual.html#tracking-messages

  1. You can ask Mailgun if something has happened by sending a request to api.mailgun.net regularly. See example code here (select C# from the "Code sample preference" menu at the top): https://documentation.mailgun.com/user_manual.html#events
    To use the code example, you need to include RestSharp in your project (for example through NuGet). You can probably also change the code a bit and use .NET's built-in WebClient instead.
  2. You can also tell Mailgun to notify your site whenever something happens, using webhooks. Here, you need to create a separate page (.aspx/.ashx), and register the page's url in your Mailgun control panel. That page will then receive a POST request from time to time, which your code needs to parse.
    https://documentation.mailgun.com/user_manual.html#webhooks

Edit:

Here is an example of a Mailgun webhook, where someone has created the page www.YOURDOMAINHERE.com/sms.aspx: https://stackoverflow.com/a/8489098/1869660

The data which is sent from Mailgun can be found in Request.Params

To make sure ValidateRequest="false" works in the example, look at this question: ValidateRequest="false" doesn't work in Asp.Net 4

Community
  • 1
  • 1
Sphinxxx
  • 12,484
  • 4
  • 54
  • 84
  • What you are describing would require some sort of background service to be running on my ISP's server, querying Mailgun. I doubt an ISP will install a custom service like that. –  May 01 '16 at 02:30
  • I did see the documentation. I did not find any examples of how to write these webhooks, though. –  May 01 '16 at 02:31
  • #1: You're right, it may not be possible to do that fully automatically in your case. #2: I have added a webhook example. – Sphinxxx May 01 '16 at 11:58
  • This might be exactly what I need. It is a "on the side" project that I am doing for free (non-profit organization), so it might take me some time to get it working. I'll leave it "unaccepted as answer" for now, so that I can easily find it if I happen to close/lose this spot. :) –  May 01 '16 at 18:11
  • Alright, good luck :) – Sphinxxx May 01 '16 at 21:03