# \[Kontaktformular\] Decorating MailService

**URL:** <https://forum.shopware.com/t/kontaktformular-decorating-mailservice/65470>\
**Category:** Programmierung\
**Created:** [12. März 2020 um 16:59 UTC](https://forum.shopware.com/t/kontaktformular-decorating-mailservice/65470 "2020-03-12T16:59:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pino](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/pino/32/14373_2.png) [@pino](https://forum.shopware.com/u/pino)\
**Post date:** [12. März 2020 um 16:59 UTC](https://forum.shopware.com/t/kontaktformular-decorating-mailservice/65470/1 "2020-03-12T16:59:18Z")

</div>

Tach zusammen,

das Kontaktformular macht seine Arbeit.&nbsp;Allerdings ist der Absender immer ich.  
D.H., wenn ich auf eine Anfrage antworte (Mailprogramm Antworten), dann schreib ich mir selbst eine E-Mail.  
Ich bin also gezwungen den Empfänger anzupassen:

- E-Mail Adresse aus dem Text suchen
- Copy/Past Empfänger  
Das empfinde ich als unnötige Schritte.

In&nbsp;Shopware\Core\Content\MailTemplate\Service\MailService wird folgendes als Absender festgelegt:

```
[120] $senderEmail = $this->systemConfigService->get('core.basicInformation.email', $salesChannelId);

[122] $senderEmail = $senderEmail ?? $this->systemConfigService->get('core.mailerSettings.senderAddress');

```

Also irgendeine Adresse die ich konfiguriert habe.

Nun wollte ich den&nbsp;MailService dekorieren und muss feststellen, dass das nicht&nbsp;geht:

> Argument 1 passed to Shopware\Core\Content\MailTemplate\Subscriber\MailSendSubscriber::\_\_construct() must be an instance of Shopware\Core\Content\MailTemplate\Service\MailService, instance of MyPlg\Core\Content\MailTemplate\Service\MailService given, called in /var/www/var/cache/dev\_h8024e86b1aab233559f2d7b50ee43088/ContainerNhPDC6d/srcShopware\_Production\_KernelDevDebugContainer.php on line 14410

Ich vermute mal, dass es an den fehlenden Interface liegen könnte.&nbsp;MailService ist einfach&nbsp;nur eine Klasse ohne&nbsp;Interface.

Hat jemand nen Tipp für mich, wie ich das umgehen kann?

---

<div class="post-metadata">

**Author:** ![mowlwurf](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@mowlwurf](https://forum.shopware.com/u/mowlwurf)\
**Post date:** [12. März 2020 um 20:23 UTC](https://forum.shopware.com/t/kontaktformular-decorating-mailservice/65470/2 "2020-03-12T20:23:48Z")

</div>

Hi,

ja ist richtig liegt am fehlenden Interface. Aber Du könntest die service id “Shopware\Core\Content\MailTemplate\Service\MailService” im Container mit Deiner eigenen überschreiben. Müsstest dafür in Deiner Plugin Klasse eine build Funktion einbauen. Ähnlich wie beim FroshDevelopmentHepler

```
public function build(ContainerBuilder $container): void
    {
        $container->addCompilerPass(new DisableTwigCacheCompilerPass());
        $container->addCompilerPass(new CustomProfilerExtensions());
        $container->addCompilerPass(new BuildEntityDefinitionNamesCompilerPass());
        parent::build($container);
    }

```

Könntest dann theoretisch eine Klasse mit dem Shopware Mailservice als Parent erstellen, müsstest nur die private Funktionen (da diese nicht ans Child vererbt werden) mitaufnehmen, und die gewünschte Funktion anpassen.

---

<div class="post-metadata">

**Author:** ![shyim](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/shyim/32/7681_2.png) [@shyim](https://forum.shopware.com/u/shyim)\
**Post date:** [12. März 2020 um 21:14 UTC](https://forum.shopware.com/t/kontaktformular-decorating-mailservice/65470/3 "2020-03-12T21:14:41Z")

</div>

Noch besser wäre es&nbsp;wenn du ihn trotzdem dekorierst aber von der Shopware Klasse ableitest. Und dann ihn so verwendest als hättest du ein Interface.

---

<div class="post-metadata">

**Author:** ![pino](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/pino/32/14373_2.png) [@pino](https://forum.shopware.com/u/pino)\
**Post date:** [13. März 2020 um 10:04 UTC](https://forum.shopware.com/t/kontaktformular-decorating-mailservice/65470/4 "2020-03-13T10:04:27Z")

</div>

danke euch beiden.

ich hab den service nun überschrieben:

und die von der Klasse abegleitet:

```
class MailService extends BaseMailService {
...
}

```

die ganzen privaten methoden und variablen hab ich also komplett übernommen.

---

<div class="post-metadata">

**Author:** ![h\_lohaus](https://avatars.discourse-cdn.com/v4/letter/h/a587f6/32.png) [@h\_lohaus](https://forum.shopware.com/u/h_lohaus)\
**Post date:** [13. März 2020 um 10:23 UTC](https://forum.shopware.com/t/kontaktformular-decorating-mailservice/65470/5 "2020-03-13T10:23:08Z")

</div>

btw. Mit 6.2 wird alles besser. Dank PullRequests. Es gibt dort Interfaces und neue Events.
