Pierre Prinetti
Pierre Prinetti

Reputation: 9652

How to forward incoming mail to an HTTP endpoint?

I would like to programmatically receive e-mails without the hassle of handling standard mail protocols (SMTP).

Is it possible to set a Mailgun route to forward (POST) all mail to an HTTP(S) endpoint? Currently, it seems to me that the provided webhooks can only notify you, rather than POST an entire email.

Upvotes: 3

Views: 4053

Answers (3)

Sayed
Sayed

Reputation: 631

For someone landing here still looking for an answer, here's what I needed and what I did:

I needed any emails sent to any random (even non-existent) email address on my domain, eg, mydomain.com to be forwarded to my webhook with the contents of the email. All of these email clients (Sendgrid, Zoho, Mailjet, etc.) do provide such APIs, often called "Incoming email Parser API", but they all require you to have these "delivery" email addresses to be existent (costing your per-user cost for every new email address on your domain). So, if you've 100,000 users, you'd need 100,000 email Ids to be registered with these vendors for these emails to be forwarded to your webhook correctly.

Except, that's not the right solution. I can't pay for every email on my domain, specially when the users don't use my domain for emailing purposes. I, rather, was setting some random email for the user (say, [email protected]), and needed all the emails sent to this email to be forwarded to my webhook so that I could inform my user on his/her registered email.

To do that, you could achieve it in 02 ways:

  1. Use an "MX forwarder". I've used improvxmx.com, but it lets you use webhooks only in premium plans. All you need to do is point your domain's MX address to the record provided in your account.
  2. Use something like "Zapier". Have all the emails sent to your gmail account on behalf of user. You can do this by appending userId to your gmail ID (say, for [email protected], it becomes [email protected], where appUser123 is the UID of the user from your app). Then, zapier can pick emails from your gmail account and have them forwarded to your webhook. But again, Zapier's webhooks are also premium plans.

I was here looking for an alternative free solution.

Upvotes: 0

Austin Ayers
Austin Ayers

Reputation: 21

Mailgun supports forwarding messages to an HTTP endpoint using the Forward action under routes. You can forward in Sumo Parsed format OR just post the actual mime content using a flag within the Forward URL. https://documentation.mailgun.com/en/latest/user_manual.html#routes

When you specify a URL of your application as a route destination through a forward() action, Mailgun will perform an HTTP POST request into it using one of two following formats:

Fully parsed: Mailgun will parse the message, transcode it into UTF-8 encoding, process attachments, and attempt to separate quoted parts from the actual message. This is the preferred option. Raw MIME: message is posted as-is. In this case you are responsible for parsing MIME. To receive raw MIME messages, the destination URL must end with mime.

Upvotes: 2

bvanvugt
bvanvugt

Reputation: 1242

The Mailgun Routes API will notify you, and also provide a URL where you can download the full email content.

If that is not sufficient, you might want to look at SendGrid or Mandrill. I believe Mandrill POSTs the entire email data in their webhook.

Upvotes: 5

Related Questions