Gmail to Freshdesk - Convert Emails into Support Tickets


Create customer support tickets in Freskdesk with email messages in Gmail using Google Apps Script

Published in: Google Apps Script - Gmail

Custom support systems like Freshdesk, Zoho Desk, or Zendesk offer an email address - like - for quickly creating customer tickets without having to fill any complicated web forms.

Any email message sent to your support email address automatically gets converted into a ticket and a unique ticket ID gets assigned to the support request.

When a ticket is created from an email address, the email subject becomes the ticket title, the email body becomes the ticket description and the most important part, the customer’s name and email address is pulled from the FROM field of the email message header. This is important because when your helpdesk agents respond to a ticket, the replies are sent directly to the customer.

Email Ticketing with Gmail Forwards - The Problem

This system works perfect when the customer sends an email message directly to the help desk email but imagine if they send an email to you, the support agent, and it is your job to create a support ticket from the customer’s email.

Now if you forward the customer’s email message received in your Gmail mailbox to Freshdesk, the ticket would still be created but since it will have your name and email in the FROM field, the helpdesk software would assign you as the customer even though you are just creating a support ticket on behalf of the customer. If any agent responds to such a ticket, you’ll be part of all the communication and not the original customer since their email address is no part of the support ticket created from the forwarded email.

I have been exploring Freskdesk and faced a similar issue. How to easily create support tickets from existing email messages in Gmail. Couldn’t find a readymade solution so decided to build one using the Freshdesk API and Google Apps Script.

Convert Gmail Emails to Freshdesk Tickets

To get started, you’ll need the domain (where your Freshdesk site is hosted) and the API Key that is available under your Freshdesk profile page.

Next, go to your Gmail and create a label - say Freshdesk. Now you can simply drag customer emails from your Gmail Inbox to this new Freshdesk label and they’ll be automatically converted into customer tickets. Unlike email forwards, here the tickets would be created with the customer’s name and email address as the requestor.

const GMAIL_LABEL_NAME = 'Freshdesk';
const FRESHDESK_API_KEY = 'Your API Key';
const FRESHDESK_SUBDOMAIN = 'Your subdomain';

const connectToFreshdesk_ = (postData) => {
  const API = `https://${FRESHDESK_SUBDOMAIN}`;
  const response = UrlFetchApp.fetch(API, {
    method: 'POST',
    contentType: 'application/json',
    muteHttpExceptions: true,
    payload: JSON.stringify(postData),
    headers: {
      'Content-type': 'application/json',
        'Basic ' + Utilities.base64Encode(FRESHDESK_API_KEY + ':X'),
  if (!/^2/.test(String(response.getResponseCode()))) {
    console.error('Cannot create ticket', response.getContentText());

const createSupportTicket_ = (message) => {
  const [email, ...names] = message
    .replace(/[<>"]/g, '')
    .split(' ')
  const postData = {
    subject: message.getSubject(),
    description: message.getBody(),
    name: names.reverse().join(' '),
    source: 3,
    status: 3,
    priority: 2,
  connectToFreshdesk_('', postData);

const gmailToFreshdesk = () => {
  const label = GmailApp.getUserLabelByName(GMAIL_LABEL_NAME);
  label.getThreads(0, 20).forEach((thread) => {
    const [message] = thread.getMessages().reverse();

Inside the Google Script editor, go to Edit > Current Project Triggers > Add Triggers and create a new time based trigger that runs every 15 minutes for the gmailToFreshdesk method.

Now the Google Script will connect to your Gmail every 15 minutes, finds any new email messages in the specified label and convert them to Freskdesk support tickets. It will also remove the email message from the label after the ticket is created.

No Gmail Sending Limits Apply

With Apps Script, you need not worry about Gmail sending limits since the tickets are created with API calls and your not sending (forwarding) email anywhere.

📮  Subscribe to our Email Newsletter for Google tips and tutorials!
Published in: Google Apps Script - Gmail

Looking for something? Find here!

Meet the Author

Web Geek, Google Developer Expert
Amit Agarwal

Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India. He is the developer of Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

Get in touch

Google Add-ons

Do more with your Gmail and GSuite account

We build bespoke solutions that use the capabilities and the features of Google Workspace for automating business processes and driving work productivity.

  1. Mail Merge with Attachments
    Send personalized email to your Google Contact with a Google Sheet and Gmail
  2. Save Emails and Attachments
    Download email messages and file attachments from Gmail to your Google Drive
  3. Google Forms Email Notifications
    Send email notifications to multiple people when a new Google Form is submitted
  4. Document Studio
    Create beautiful pixel perfect documents merging data from Google Sheets and Google Forms
  5. Creator Studio for Google Slides
    Turn your Google Slides presentations into animated GIFs and videos for uploading to YouTube