> ## 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.

# Custom emails

In addition to the regular emails that any shop can send when typical situations occur, for example when a certain stock level for a product is reached, it can sometimes be useful to send automated emails to the person responsible for the shop in situations that are relevant only to individual shops.

For example, it can be helpful if the shop carries products from various manufacturers and sends emails to those manufacturers whenever buyers order their products in the shop. This enables the manufacturers in question to check their stock of the affected products and to prepare the shipment so that they can dispatch as soon as the order is placed.

WEBSALE V8s generally allows you to prepare custom emails for such needs, that is, emails configured by the shop operator that are sent to previously defined recipients. Delivery is triggered when a buyer visits a particular page, for example by clicking a specific product detail page, or when a particular shop state is reached, for example a logged-in customer, or is not reached, for example a search for product A without results. We pick up the latter case in the integration examples below.

## How it works

The shop automatically sends an email to a statically configured recipient address when a specific page is clicked or a particular state of the shop is reached or not reached.

> [!NOTE]
>
> The email cannot be sent to dynamic recipients, for example not to a shop customer, because the recipient address has to be stored statically in the shop configuration `shop.config`.

## Integration

### Step 1: Activation

No activation on the part of WEBSALE is required for this function.

### Step 2: Adjust the shop configuration

In your shop configuration `shop.config`, create a `GenericEmails` section if it does not yet exist, along with a `+Entry` subsection. The `+Entry` subsections can be repeated up to 20 times for different emails. Configure the following parameters:

```ini theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
<GenericEmails>
   ...
   <+Entry>
      Address          = info@mein-shop.de
      Subject-Txt      = Betreff xY
      SenderAddress    = absender@mein-shop.de
      SenderName       = Mein Shop
      Template         = mail_xY.htm
      ID               = beispiel_id
   </+Entry>
   ...
</GenericEmails>
```

Reference: GenericEmails section&#x20;

### Step 3: Adjust the shop templates

Now adjust the desired shop templates in order to control the sending of the email. To do this, use the tag `WS-SendGenericEmail()`. In the argument of the tag, enter the string that you specified in step 2 as the value of the parameter `ID`.

**Example 1, search result page.** The email is sent when the buyer has performed a search and has reached the search result page.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
<body>
   ...
   ~WS-SendGenericEmail(Search)~
   ...
</body>
```

The content of the mail can be: "A customer has visited the shop's search page."

**Example 2, search result page without hits.** The email is sent when the buyer has performed a search and has reached the search result page, but the search yielded no results. This is the combination of reaching the page and a particular state.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
<body>
   ...
   {!WS-SearchResults}
      ~WS-SendGenericEmail(Search)~
   {/!WS-SearchResults}
   ...
</body>
```

The content of the mail can be: "A customer has visited the shop's search page, but no hits were found for their search."

**Example 3, two mails for two states of the same page.** Mail 1 with the ID `SuccessSearch` is sent when the buyer has found something, mail 2 with the ID `EmptySearch` when the search was unsuccessful. This is the combination of reaching the page and different states. The prerequisite is that two sections with the corresponding IDs have been created in the shop configuration `shop.config`.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
<body>
   ...
   {WS-SearchResults}
      <!-- Suchergebnisseite mit Ergebnis -->
      ~WS-SendGenericEmail(SuccessSearch)~
   {/WS-SearchResults}

   {!WS-SearchResults}
      <!-- Suchergebnisseite ohne Ergebnis -->
      ~WS-SendGenericEmail(EmptySearch)~
   {/!WS-SearchResults}
   ...
</body>
```

The content of mail 1 with the ID `SuccessSearch` can be: "A customer has visited the shop's search page, and hits were found for their search."

The content of mail 2 with the ID `EmptySearch` can be: "A customer has visited the shop's search page, but their search returned no hits."

**Example 4, empty category.** On the product overview page (`ws_category.htm`), the email is sent when the category contains no products.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
<body>
   ...
   {CAT-Data}
      ~DC-FPCategoryHasProducts_set(yes)~
   {/CAT-Data}

   {!DC-FPCategoryHasProducts(yes)}
      ~DC-FPCatIndex_set($CAT-Index$)~
      ~DC-FPCatName_set($CAT-Name$)~
      ~WS-SendGenericEmail(EmptyCategory)~
   {/!DC-FPCategoryHasProducts(yes)}
   ...
</body>
```

The content of the mail can be: "The category with the name `~DC-FPCatName~` and the category index `~DC-FPCatIndex~` is empty; it does not contain any products."

Reference: WS-SendGenericEmail()&#x20;

### Step 4: Create the email template

Create a template and save it under the same name that is specified in the `GenericEmails` section as the value of the parameter `Template`, in your template directory, for example `benutzer/templates/translation`.

The content of the template depends on how the delivery is being controlled.

Once you have completed all steps, the function is fully integrated and can be tested and put into use.


## Related topics

- [messages - Event-driven emails](https://dokumentation.websale.de/en/konfiguration/messages-ereignisgesteuerte-e-mails.md)
- [Configuration deep links](https://dokumentation.websale.de/en/admin-interface/konfigurations-deeplinks.md)
- [Email notifications: overview](https://dokumentation.websale.de/en/v8s/e-mails/e-mail-benachrichtigungen-ueberblick.md)
- [Emails](https://dokumentation.websale.de/en/v8s/referenz/konfigurationen/shopkonfiguration-shop-config/e-mails.md)
- [Emails & email settings](https://dokumentation.websale.de/en/konfiguration/e-mails-e-mail-einstellungen.md)


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