.. meta::
   :description: How email works in Znuny: how a customer mail becomes a ticket, how a reply finds its ticket and what an agent reply sends out.
   :keywords: znuny email, incoming email, follow-up, ticket number in subject, postmaster, agent reply, email ticket, mail to ticket

.. _PageNavigation concepts_email_index:

Email in Znuny
##############

Email is the most common way customers reach a service desk. Znuny does not keep mails as loose messages. Every mail ends up as an :ref:`article <PageNavigation concepts_articles_index>` in a ticket, so the whole conversation with a customer stays in one place, in the order it happened.

A customer mail becomes a ticket
********************************

Maria Keller writes to ``support@example.com``: "The printer on floor 2 is offline." When Znuny picks up the mail, three things decide what happens next:

1. **A new ticket is created.** The subject becomes the ticket title, the mail itself becomes the first article, and Maria is set as the customer.
2. **The queue comes from the address the mail was sent to.** ``support@example.com`` is a system address, and each system address belongs to a queue. Mails to ``support@example.com`` land in the Service Desk queue, mails to ``sales@example.com`` in the Sales queue. See :ref:`System Email Addresses <PageNavigation system_email>`.
3. **A ticket number is assigned.** The number identifies the ticket in every later mail. In the default format it looks like ``2026120321000385``.

Znuny gets the mail in one of two ways. A :ref:`mail account <PageNavigation email_postmaster_mail_account>` fetches it from a mailbox on a regular schedule, or the mail server hands it over directly.

.. note::

   Postmaster filters can change what happens to a mail before the ticket is created, for example to put mails from a monitoring system into another queue, set a priority, or ignore automatic replies. See :ref:`Email Filtering <PageNavigation admin_automation_postmaster_filter_index>`. Mails can also carry ``X-Znuny`` headers that set ticket values directly, see :ref:`Mail accounts <PageNavigation email_postmaster_mail_account>`.

A reply finds its ticket
************************

Maria answers a mail from the service desk. The answer should land in her existing ticket, not open a second one. Znuny checks, in this order, whether an incoming mail belongs to a ticket:

1. **Ticket number in the subject.** A subject such as ``Re: [Ticket#2026120321000385] Printer on floor 2 is offline`` is matched to ticket ``2026120321000385``. This works because every mail an agent sends carries the number in its subject. Customer mail programs keep it when they reply, and they add their own prefix such as ``AW:`` or ``Re:`` in front.
2. **Mail headers.** If the number is gone from the subject, for example because Maria rewrote it, Znuny looks at the ``In-Reply-To`` and ``References`` headers. These point to the mail she is answering and lead to the same ticket.
3. **No match.** The mail starts a new ticket, even if the subject is the same as an existing ticket.

When a mail matches, it is added to the ticket as a new customer article.

Which of these checks run, and whether a ticket number appears at the start or end of the subject, is controlled by System Configuration. The most useful settings are:

- ``Ticket::Hook`` and ``Ticket::SubjectFormat`` for the text and position of the ticket number in the subject.
- ``Ticket::NumberGenerator`` for the number format.
- ``PostMaster::CheckFollowUpModule###0100-Subject`` and ``PostMaster::CheckFollowUpModule###0200-References`` for the two checks above. Further checks, for example one that searches the mail body, are available but switched off by default.

Replies to closed tickets
=========================

When Maria replies to a ticket that is already closed, the follow-up option of the queue decides:

- **possible:** the ticket is reopened and the reply is added to it.
- **reject:** the reply is not added. The sender gets the *reject* auto response, if one is set up.
- **new ticket:** a new ticket is created and linked to the old one.

The default for a new queue is *possible*. The follow-up options are set per queue, see :ref:`Queues <PageNavigation admin_queues_index>`.

An agent reply goes out
***********************

An agent opens the ticket and chooses **Reply** on Maria's article. Znuny fills the form for the agent:

- The recipient is the sender of the article.
- The subject starts with ``Re:`` and contains the ticket number.
- The sender address is the system address of the ticket's queue, so Maria sees ``support@example.com`` and not the agent's personal address.
- Salutation, text template and signature come from the queue and from :ref:`templates <PageNavigation admin_communication_templates_index>`, so every agent answers in the same form.

When the agent sends the reply, it is stored in the ticket as an article from the agent and goes out through the module set in ``SendmailModule``. By default this is ``Sendmail``, which hands the mail to the sendmail program of the server. Most installations switch it to an SMTP mail server, see :ref:`SMTP Settings <admin_smtp_settings>`. With ``MultiSendmail`` each sender address can have its own :ref:`outbound email profile <PageNavigation outbound_email_profiles>`.

The mail does not leave at the moment the agent clicks send. Znuny puts it in a mail queue, and a daemon task sends the queued mails every minute by default (task ``MailQueueSend`` in System Configuration). If the mail server refuses a mail, Znuny tries again, three times by default (``MailQueue``, ``ItemMaxAttempts``). When all attempts fail, the agent sees a message in the ticket and can use **Resend** in the article menu to correct the address and send the mail again. See :ref:`Resend an Email <PageNavigation ticketviews_agentticketmailresend>`. Failures are only reported back with the SMTP modules. With plain ``Sendmail`` a failed mail is not reported.

The ticket is locked to the agent while they work on it. See :ref:`Ticket Lock <PageNavigation concepts_locking_index>`.

Notes that are not for the customer
***********************************

Agents can add an internal note to a ticket. It is stored as an article too, but it is never sent by mail and the customer cannot see it. Use it for what the team needs to know and the customer does not, for example the result of a call with a supplier.

Automatic mails
***************

Besides replies from agents, Znuny sends mails on its own:

- **Auto responses** confirm to the customer that a mail arrived and a ticket was created, or that a follow-up was received. See :ref:`Automatic Responses <PageNavigation admin_communication_autoresponses_index>`.
- **Ticket notifications** inform agents and customers about events such as a new ticket, a new follow-up or an escalation. See :ref:`Ticket Notifications <PageNavigation admin_automation_ticket-notification_index>`.

Sending mails to Znuny from systems that answer automatically can cause loops. Znuny detects loops and stops answering, and postmaster filters can ignore such mails from the start.

What to read next
*****************

- :ref:`Articles <PageNavigation concepts_articles_index>`
- :ref:`Mail accounts <PageNavigation email_postmaster_mail_account>`
- :ref:`Email Filtering <PageNavigation admin_automation_postmaster_filter_index>`
- :ref:`Queues <PageNavigation admin_queues_index>`
