Turn Incoming Emails Into Tickets And Replies

BeDesk can automatically convert incoming emails into new support tickets or add them as replies to existing tickets. This allows you to manage all your customer communication directly from the helpdesk.

To get started, you'll need to configure an email handler. These are different methods BeDesk can use to process incoming mail. You can enable and configure one or more handlers from the admin panel.

Navigate to Admin > Settings > Email page and select the Incoming tab.

Here, you'll find several handlers to choose from. Let's go over each one.

IMAP

The IMAP handler is the recommended method if you're using a third-party email provider like Gmail, Outlook, Yahoo, or any standard email host. It works by periodically checking a specified email account for new messages.

Prerequisites:

To set it up:

  1. On the incoming email settings page, click the + Add connection button in the IMAP section.

  2. Enter the IMAP credentials for your email account (this is usually the same email and password you use to log in to your webmail).

  3. Optionally, you can specify a folder/label. If you do, BeDesk will only process emails that are in that specific folder.

  4. Click Save.

By default, this method will only convert emails received after you've established the connection.

Gmail API

For Gmail users, this is a more advanced alternative to IMAP that can process incoming emails almost instantly. It uses the official Gmail API and Google Cloud's Pub/Sub service to receive real-time notifications about new emails.

Step 1: Configure Google Cloud Project

  1. First, follow the guide to configure Google social login. You only need to enter the Client ID and Client Secret in BeDesk; you can keep the social login feature itself disabled if you wish.

  2. Go to the Google Cloud Console, click Library, find the Gmail API, and make sure it is Enabled.

  3. Go to the Google Cloud Pub/Sub page within the same project.

Step 2: Create a Pub/Sub Topic

  1. Go to the Topics section and click Create Topic.

  2. Enter a Topic ID (e.g., bedesk-emails) and click Create.

  3. Select the checkbox next to your new topic and click Add Principal in the permissions panel on the right.

  4. In the New Principals field, paste gmail-api-push@system.gserviceaccount.com.

  5. For the Role, select Pub/Sub Publisher.

  6. Click Save.

Step 3: Create a Pub/Sub Subscription

  1. Go to the Subscriptions section and click Create Subscription.

  2. Enter a Subscription ID.

  3. Under Select a Cloud Pub/Sub topic, choose the topic you created in the previous step.

  4. For Delivery Type, select Push.

  5. In the Endpoint URL field, enter: https://your-site.com/tickets/mail/incoming/gmail (replace your-site.com with your BeDesk URL). Note: Google requires an https:// URL.

  6. Set the Retry Policy to Retry after exponential backoff delay and click Create.

Step 4: Configure BeDesk

  1. Return to your BeDesk incoming email settings page (Admin > Settings > Email > Incoming).

  2. Enable the Gmail API handler.

  3. In the Gmail topic name field, enter the full topic name you created (e.g., projects/your-project-id/topics/bedesk-emails).

  4. Click Connect gmail account and authorize the Google account you want to fetch emails from.

Piping

Email piping is a direct and efficient method if your hosting provider (using a control panel like cPanel) allows it. Instead of checking for new mail, your email server will immediately "pipe" incoming emails directly to a BeDesk script for processing.

To set it up:

  1. Enable the Pipe handler in your BeDesk settings.

  2. In your hosting control panel, find the email forwarding or routing settings.

  3. Set up a forwarder to pipe emails to the following script path: /path/to/bedesk/pipe.php (replace /path/to/bedesk/ with the actual path on your server).

Example for cPanel:

  1. Go to cPanel > Email > Forwarders > Add Forwarder.

  2. In Address to Forward, enter the email address you want to use.

  3. Expand Advanced Options and select Pipe to a Program.

  4. In the text box, enter the full path: path/to/bedesk/pipe.php.

  5. Click Add Forwarder.

REST API

This method is for advanced use cases, such as integrating with a third-party application or another website that can send webhook notifications. You can send email data to BeDesk via a simple HTTP POST request.

To set it up:

  1. Enable the Rest API handler in your BeDesk settings.

  2. Obtain an API Access Token from your agent profile by navigating to your-site.com/account/settings.

  3. When you receive an email, send an HTTP POST request to the following endpoint: https://your-site.com/api/v1/tickets/mail/incoming.

  4. Include the API Access Token in the Authorization header.

You can send the raw email content (MIME format) as the request body or send it as formatted JSON like this:

{
      "headers": { "From": "some@email.com", "Reply-To": "some-other@email.com" },
      "body": {
        "plain": "email body",
        "html": "email body",
        "stripped-html": "email body"
      },
      "attachments": [
        {
          "original_name": "file.jpg",
          "mime_type": "image/jpg",
          "size": 154654,
          "contents": "base64 encoded file content",
          "extension": "jpg",
          "cid": "<45478qwe>"
        }
      ]
    }

Mailgun

Mailgun is a powerful email service that can handle your incoming and outgoing mail. You can configure it to receive all your support emails and forward them directly to BeDesk.

Prerequisites:

To set it up:

  1. In your Mailgun account, set up the MX records for your domain or a dedicated subdomain (e.g., support.your-site.com). This directs mail sent to that domain to Mailgun's servers.

  2. Navigate to the Receiving section in Mailgun and create a new Route.

  3. Set the Expression Type to Catch All.

  4. Enter the following URL: https://your-site.com/tickets/mail/incoming/mailgun in Store and notify field (replace your-site.com with your actual site url)

  5. Create the route. Mailgun will now notify BeDesk whenever it receives an email.

  6. (Optional but Recommended) Go to Receiving > Webhooks, select Permanent Failure as the event type, and enter https://your-site.com/tickets/mail/failed/mailgun as the URL. This will notify BeDesk about any failed email deliveries.

If you already have MX records on your domain set (for example to gmail), you can set mailgun mx records for a sub-domain. For example: support.your-site.com, now you can forward emails to support@support.your-site.com. This way you will receive emails to both your gmail inbox and BeDesk.