# Parse API: inbound emails

Info
Parse API is available only for users on paid Mailjet plans (Premium 50k and above). Check our [plans](https://app.mailjet.com/subscription) and [pricing pages](https://www.mailjet.com/pricing/) for more information.

The Parse API allows you to have inbound emails parsed and their content delivered to a webhook of your choice.

It will make the processing of inbound messages easier as Mailjet will do all the job of sifting through and organizing all the information in headers, content and attachments. What's left to do is just to save the information in your CRM or database.

## Basic Setup

cURL
```shell
# Create : ParseRoute description
curl -s \
	-X POST \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3/REST/parseroute \
	-H 'Content-Type: application/json' \
	-d '{
		"Url":"https://www.mydomain.com/mj_parse.php"
	}'
```

PHP
```php
<?php
/*
Create : ParseRoute description
*/
require 'vendor/autoload.php';
use \Mailjet\Resources;
$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));
$body = [
    'Url' => "https://www.mydomain.com/mj_parse.php"
];
$response = $mj->post(Resources::$Parseroute, ['body' => $body]);
$response->success() && var_dump($response->getData());
?>
```

Node.js
```javascript
/**
 *
 * Create : ParseRoute description
 *
 */
const mailjet = require ('node-mailjet')
	.connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE)
const request = mailjet
	.post("parseroute")
	.request({
		"Url":"https://www.mydomain.com/mj_parse.php"
	})
request
	.then((result) => {
		console.log(result.body)
	})
	.catch((err) => {
		console.log(err.statusCode)
	})
```

Ruby
```ruby
# Create : ParseRoute description
require 'mailjet'
Mailjet.configure do |config|
  config.api_key = ENV['MJ_APIKEY_PUBLIC']
  config.secret_key = ENV['MJ_APIKEY_PRIVATE']  
end
variable = Mailjet::Parseroute.create(url: "https://www.mydomain.com/mj_parse.php"
)
p variable.attributes['Data']
```

Python
```python
"""
Create : ParseRoute description
"""
from mailjet_rest import Client
import os
api_key = os.environ['MJ_APIKEY_PUBLIC']
api_secret = os.environ['MJ_APIKEY_PRIVATE']
mailjet = Client(auth=(api_key, api_secret))
data = {
  'Url': 'https://www.mydomain.com/mj_parse.php'
}
result = mailjet.parseroute.create(data=data)
print result.status_code
print result.json()
```

Java
```java
package com.my.project;
import com.mailjet.client.errors.MailjetException;
import com.mailjet.client.errors.MailjetSocketTimeoutException;
import com.mailjet.client.MailjetClient;
import com.mailjet.client.MailjetRequest;
import com.mailjet.client.MailjetResponse;
import com.mailjet.client.resource.Parseroute;
import org.json.JSONArray;
import org.json.JSONObject;
public class MyClass {
    /**
     * Create : ParseRoute description
     */
    public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {
      MailjetClient client;
      MailjetRequest request;
      MailjetResponse response;
      client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"));
      request = new MailjetRequest(Parseroute.resource)
			.property(Parseroute.URL, "https://www.mydomain.com/mj_parse.php");
      response = client.post(request);
      System.out.println(response.getStatus());
      System.out.println(response.getData());
    }
}
```

Go
```go
/*
Create : ParseRoute description
*/
package main
import (
	"fmt"
	"log"
	"os"
	mailjet "github.com/mailjet/mailjet-apiv3-go"
	"github.com/mailjet/mailjet-apiv3-go/resources"
)
func main () {
	mailjetClient := NewMailjetClient(os.Getenv("MJ_APIKEY_PUBLIC"), os.Getenv("MJ_APIKEY_PRIVATE"))
	var data []resources.Parseroute
	mr := &Request{
	  Resource: "parseroute",
	}
	fmr := &FullRequest{
	  Info: mr,
	  Payload: &resources.Parseroute {
      Url: "https://www.mydomain.com/mj_parse.php",
    },
	}
	err := mailjetClient.Post(fmr, &data)
	if err != nil {
	  fmt.Println(err)
	}
	fmt.Printf("Data array: %+v\n", data)
}
```

C#
```csharp
using Mailjet.Client;
using Mailjet.Client.Resources;
using System;
using Newtonsoft.Json.Linq;
namespace Mailjet.ConsoleApplication
{
   class Program
   {
      /// <summary>
      /// Create : ParseRoute description
      /// </summary>
      static void Main(string[] args)
      {
         RunAsync().Wait();
      }
      static async Task RunAsync()
      {
         MailjetClient client = new MailjetClient(Environment.GetEnvironmentVariable("MJ_APIKEY_PUBLIC"), Environment.GetEnvironmentVariable("MJ_APIKEY_PRIVATE"));
         MailjetRequest request = new MailjetRequest
         {
            Resource = Parseroute.Resource,
         }
            .Property(Parseroute.Url, "https://www.mydomain.com/mj_parse.php");
         MailjetResponse response = await client.PostAsync(request);
         if (response.IsSuccessStatusCode)
         {
            Console.WriteLine(string.Format("Total: {0}, Count: {1}\n", response.GetTotal(), response.GetCount()));
            Console.WriteLine(response.GetData());
         }
         else
         {
            Console.WriteLine(string.Format("StatusCode: {0}\n", response.StatusCode));
            Console.WriteLine(string.Format("ErrorInfo: {0}\n", response.GetErrorInfo()));
            Console.WriteLine(response.GetData());
            Console.WriteLine(string.Format("ErrorMessage: {0}\n", response.GetErrorMessage()));
         }
      }
   }
}
```

### API Response

```
{
	"Count": 1,
	"Data": [
		{
			"APIKeyID": "11111111",
			"Email": "16Hy-aOYhApIzTgN@parse-in1.mailjet.com",
			"ID": "1",
			"Url": "https://www.mydomain.com/mj_parse.php"
		}
	],
	"Total": 1
}
```

In order to begin receiving emails to your webhook, create a new instance of the Parse API via a `POST` request on the /parseroute resource. This call has only one mandatory property - the `Url` of the webhook (Note: URLs provided cannot be the root). Mailjet will provide an Email address (on the subdomain @parse-in1.mailjet.com) in the response, you can begin to use immediately. It can be used as a Reply-to Email address for example.

We strongly recommend using a secure (HTTPS) URL in combination with a basic authentification to make sure data cannot be intercepted, and that only our servers can send you data.

E.g.: `https://username:password@www.example.com/mailjet_parser.php`

You can also specify a port in your webhook URL.

E.g.: `https://www.example.com:123/mailjet_triggers.php`

Info
Mailjet provides only one Email address (on the subdomain @parse-in1.mailjet.com) per API key.

Parse API also allows you to use your own email address and domain using the `Email` property in the /parseroute resource. Visit use your own domain section for more information on how to setup your DNS and your `parseroute`.