> ## Documentation Index
> Fetch the complete documentation index at: https://dokumentation.websale.de/llms.txt
> Use this file to discover all available pages before exploring further.

# MAIL- (External mail systems)

> Loop through the attachments of a shop email in the template for an external mail system and pass on name, type and Base64 content.

If the shop does not send its emails itself but via an external mail system, it does not send that system the finished email, but the data from which the system builds the email. There is a separate template for this, stored as `ExternMailTemplate`.

The attachments are the part of this data that cannot simply be passed on as text. The `MAIL-` tags provide them: for each attachment, the file name, the type of attachment and the content in Base64 encoding.

The shop system maintains two separate lists. One contains the file attachments, the other the attachments generated from an HTML template. Both are treated the same, and each has its own four tags.

Guide: Sending shop emails via an external mail system

## Looping through the attachments

`MAIL-FileAttachment` and `MAIL-HTMLAttachment` are loops over the respective list. As area tags, they check whether any attachments of this type exist at all.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{MAIL-FileAttachment}
   {@MAIL-FileAttachment}
      <attachment>
         <name>~MAIL-FileAttachment_Name~</name>
         <type>~MAIL-FileAttachment_Type~</type>
         <content>~MAIL-FileAttachment_ContentB64~</content>
      </attachment>
   {/@MAIL-FileAttachment}
{/MAIL-FileAttachment}

{!MAIL-FileAttachment}
   <!-- keine Dateianhänge vorhanden -->
{/!MAIL-FileAttachment}
```

The same applies to the HTML attachments with `MAIL-HTMLAttachment`.

> [!WARNING]
>
> The two tags are **not** single tags. `~MAIL-FileAttachment~` outputs nothing and is treated as an invalid tag. You retrieve the details of an attachment exclusively via the three suffix tags, and only within the loop.

> [!WARNING]
>
> The three suffix tags strictly require the loop. If they are only inside the area tag `{MAIL-FileAttachment}` without the loop in it, the shop system accesses an entry before the start of the list. The result is undefined. Therefore, always open `{@MAIL-FileAttachment}`.

## The details for each attachment

| Tag | Returns |
| - | - |
| `MAIL-FileAttachment_Name` | the file name of the attachment |
| `MAIL-FileAttachment_Type` | the type of attachment as a number |
| `MAIL-FileAttachment_ContentB64` | the content, Base64-encoded |

The HTML variants are named accordingly `MAIL-HTMLAttachment_Name`, `MAIL-HTMLAttachment_Type` and `MAIL-HTMLAttachment_ContentB64`.

### The types of attachments

| Value | Meaning |
| - | - |
| 0 | fixed attachment of the order confirmation |
| 1 | data sheet |
| 2 | SEPA mandate for consumers |
| 3 | SEPA mandate for business customers |
| 4 | order overview as PDF |

> [!NOTE]
>
> The type lets you treat attachments differently in the passed data record, for example to name the SEPA mandate differently from a data sheet. The shop system itself does not distinguish by type when sending.

> [!NOTE]
>
> `ContentB64` always returns the content Base64-encoded, even for the HTML attachments, whose content is actually text. The external mail system thus gets the same format for both lists.

## The loop only runs once

> [!WARNING]
>
> After the pass, the shop system empties the list. A second loop over the same attachments returns nothing, and the area tag `{MAIL-FileAttachment}` no longer takes effect afterward either. Both lists behave this way, each on its own.
>
> This determines the order in the template: check first, then loop. If you still need to know after the loop whether there were attachments, store that beforehand in a design parameter.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{MAIL-FileAttachment}
   ~DC-FPMail_set(hatAnhaenge)~
   {@MAIL-FileAttachment}
      ...
   {/@MAIL-FileAttachment}
{/MAIL-FileAttachment}

{DC-FPMail(hatAnhaenge)}
   <!-- auch nach der Schleife noch auswertbar -->
{/DC-FPMail(hatAnhaenge)}
```

Reference: DC- (Parameters)

## The tags at a glance

| Tag | Single tag | Area tag | Negative area tag | Loop tag |
| - | - | - | - | - |
| `MAIL-FileAttachment` | – | yes | yes | yes |
| `MAIL-FileAttachment_Name` | yes | – | – | – |
| `MAIL-FileAttachment_Type` | yes | – | – | – |
| `MAIL-FileAttachment_ContentB64` | yes | – | – | – |
| `MAIL-HTMLAttachment` | – | yes | yes | yes |
| `MAIL-HTMLAttachment_Name` | yes | – | – | – |
| `MAIL-HTMLAttachment_Type` | yes | – | – | – |
| `MAIL-HTMLAttachment_ContentB64` | yes | – | – | – |

All tags apply exclusively in the template for the external mail system. On other templates, the attachment lists are not available, and the tags remain unresolved.

## Related topics

* Guide: Sending shop emails via an external mail system
* Guide: Designing shop emails
* Reference: DC- (Parameters)


## Related topics

- [Emails](https://dokumentation.websale.de/en/v8s/referenz/konfigurationen/shopkonfiguration-shop-config/e-mails.md)
- [Integrating Inxmail](https://dokumentation.websale.de/en/v8s/externe-dienste/inxmail.md)
- [IR- (BackInStockMail)](https://dokumentation.websale.de/en/v8s/referenz/tags/ir-backinstockmail.md)
- [Emails & email settings](https://dokumentation.websale.de/en/konfiguration/e-mails-e-mail-einstellungen.md)
- [Managing wishlists (admin template)](https://dokumentation.websale.de/en/v8s/referenz/tags/wunschliste/wunschlisten-verwalten.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.