---
title: Automatically create a ticket from the receiving of an email
slug: citsmart-8-en/automatically-create-a-ticket-from-the-receiving-of-an-email
description: Learn how to automate ticket creation from emails with this step-by-step guide. Discover how to set up an email account for IMAP access, configure batch routines for email verification, and create a ticket template. Included is a code snippet to extract v
docTags: 
createdAt: 2022-01-19T22:58:59.000Z
---

This functionality allows to automatically create tickets when an email message is&#x20;sent to a certain address. In this context, the solution constantly monitors&#x20;the presence of messages in the mailbox, and if some message has the status of&#x20;not read, this will be used to register a new ticket.

For example, a user should request a service by sending a message to&#x20;[service@company.com](mailto\:service@company.com), after receiving the email, the functionality, after checking&#x20;the existence of a message, automatically registers the ticket. It's important&#x20;to highlight that after the ticket registration, the email is marked as read.

## Before getting started

- [x] Make sure to configure  &#x20;an e-mail account to previously allow access via IMAP.&#x20;
- [x] Also, configure the instance to use batch routines, since the email verification is a scheduled task.

## Procedure

**Step 1 - Creating ticket template**

1. Access the functionality through the main menu `System > Automatic actions  > Incident/Request/Procedure Actions` (see Register automatic
   actions of incident/request/procedure).

**Step 2 - Set up access to the email box**

1. Create the email automatic action by accessing the main menu `System >   `
   `Settings > Automatic Action Setting Via Email`. This register is used   &#x20;to trigger the reading and register of requests (see Create automatic action via email).

**Step 3 - Create a verification routine (batch)**

1. Create a batch routine, by accessing the main menu `System > Batch Processing`   &#x20;(see Batch Processing), of "**Java Class**" type with the following content:

```java
 br.com.centralit.citcorpore.quartz.job.JobConfiguracaoAberturaAutomaticaViaEmail
```

:::hint{type="info"}
🖊 <u>**Note:**</u>

It's possible to read the title of the email sent, it stored in the field&#x20;th&#x65;**&#x20;subject** of the table *reademaildatarequest*.
:::

In addition, if there is a need to retrieve other information contained in the email fields,&#x20;as recipients marked as a copy (CC) or hidden copy (BCC) use the Rhino script below:

```java
var importNames = JavaImporter(); importNames.importPackage(Packages.br.com.citframework.util); var print = java.lang.System.out; var readEmailDataDTO = serviceRequest.getReadEmailDataDTO(); if (readEmailDataDTO!=null){ print.println("Dados do E-mail de Origem: "); print.println("From: "); print.println(readEmailDataDTO.getMessageFrom()); print.println("To: "); print.println(readEmailDataDTO.getMessageTo()); print.println("CC (Carbon Copy): "); print.println(readEmailDataDTO.getMessageCC()); }
```

