---
title: Creating Automatically a Ticket when Receiving an E-mail
slug: pink/creating-automatically-a-ticket-when-receiving-an-e-mail
description: Learn how to automatically create a ticket when an email is received at a designated address with this comprehensive guide. Discover how to configure an email account for IMAP access and set up batch routines to monitor the mailbox for new messages. Follo
docTags: 
createdAt: 2021-10-27T20:23:03.000Z
---

This functionality allows <font color="#3b9f0f">**creating an automatic ticket**</font> when an e-mail 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[ service@company.com](mailto\:service@company.com), after receiving the e-mail, the functionality. After checking&#x20;the existence of a message, automatically registers the ticket. It is important&#x20;to highlight that after the ticket registration, the e-mail is marked as read.

## Before getting started

To create a ticket through the receiving of an e-mail, it is necessary:

- [x] To configure  &#x20;an e-mail account to allow previous access via IMAP;
- [x] In addition, it is necessary  &#x20;to configure the instance to use batch routines, since the e-mail verification is a  &#x20;scheduled task.

## Procedure

### <font color="#3b9f0f">Step 1 - Creating Ticket Template</font>

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

### <font color="#3b9f0f">Step 2 - Set up Access to the E-mail box</font>

Create the e-mail automatic action by accessing the main menu `System > Settings > Automatic Action Setting via E-mail`. This register is used&#x20;to trigger the trading and register of requests (see Create automatic&#x20;action via e-mail).

### <font color="#3b9f0f">Step 3 - Create Verification Routine (batch)</font>

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>**:&#x20;**&#x49;t is possible to read the title of the e-mail sent, which is stored in the **field&#x20;subject&#x20;**&#x6F;f the **reademaildatarequest&#x20;**&#x74;able.
:::

In addition, if there is a need to retrieve other information contained in the email fields,&#x20;as recipients marked as the 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()); }
```
