{"id":13737,"date":"2023-07-31T09:37:26","date_gmt":"2023-07-31T09:37:26","guid":{"rendered":"https:\/\/www.bay20.com\/?p=13737"},"modified":"2025-05-14T15:51:44","modified_gmt":"2025-05-14T10:06:44","slug":"e-mails-senden-aus-shopware-6-programmatisch","status":"publish","type":"post","link":"https:\/\/www.bay20.com\/de\/e-mails-senden-aus-shopware-6-programmatisch\/","title":{"rendered":"Wie versendet man E-Mails aus Shopware 6 programmatisch?"},"content":{"rendered":"\n<p>Der programmgesteuerte Versand von E-Mails aus Shopware 6 kann mithilfe der von Shopware bereitgestellten Dienste und Komponenten erfolgen. Dazu m\u00fcssen Sie ein benutzerdefiniertes Plugin erstellen und den Shopware Email Service zum Versenden von E-Mails verwenden. Hier finden Sie eine Schritt-f\u00fcr-Schritt-Anleitung, die Ihnen dabei hilft, dies zu erreichen:<\/p>\n\n\n\n<p><strong>Schritt 1: Richten Sie Ihr benutzerdefiniertes Plugin ein<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Erstellen Sie ein benutzerdefiniertes Plugin in Shopware 6. Sie k\u00f6nnen das Shopware CLI-Tool verwenden, um das Plugin-Skelett zu erstellen:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>bin\/console plugin:create YourPluginName<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\"><li>Aktivieren Sie das Plugin:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>bin\/console plugin:activate YourPluginName<\/code><\/pre>\n\n\n\n<p><strong>Schritt 2: Implementierung der E-Mail-Versandlogik<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Erstellen Sie eine neue Dienstklasse in Ihrem benutzerdefinierten Plugin. Dieser Dienst wird den E-Mail-Versandprozess abwickeln. Nennen wir ihn zum Beispiel EmailSenderService.<\/li><li>Implementieren Sie eine Methode in EmailSenderService, die den E-Mail-Versand abwickeln wird. Dazu k\u00f6nnen Sie den Shopware\\Core\\Content\\MailTemplate\\Service\\MailService und den Shopware\\Core\\Framework\\Context in den Dienstkonstruktor injizieren.<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ YourPluginName\/src\/Service\/EmailSenderService.php\n\nuse Shopware\\Core\\Content\\MailTemplate\\Service\\MailService;\nuse Shopware\\Core\\Framework\\Context;\n\nclass EmailSenderService\n{\n    private $mailService;\n    private $context;\n\n    public function __construct(MailService $mailService, Context $context)\n    {\n        $this-&gt;mailService = $mailService;\n        $this-&gt;context = $context;\n    }\n\n    public function sendEmail($recipientEmail, $templateId, $senderEmail, $senderName, $data = &#91;])\n    {\n        $this-&gt;mailService-&gt;send(\n            &#91;$recipientEmail],\n            $templateId,\n            $data,\n            $this-&gt;context,\n            $senderEmail,\n            $senderName\n        );\n    }\n}\n<\/code><\/pre>\n\n\n\n<p><strong>Schritt 3: Konfigurieren Sie E-Mail-Vorlagen<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Bevor Sie E-Mails versenden, m\u00fcssen Sie die E-Mail-Vorlagen in der Shopware-Administration unter \u201eEinstellungen\u201c &amp;gt; \u201eE-Mail-Vorlagen\u201c einrichten. Erstellen Sie hier Ihre benutzerdefinierte(n) E-Mail-Vorlage(n) und notieren Sie sich die Vorlagen-ID(s).<\/li><\/ol>\n\n\n\n<p><strong>Schritt 4: Verwenden Sie den EmailSenderService in Ihrem benutzerdefinierten Code<\/strong><\/p>\n\n\n\n<p>Nun, da Sie Ihren EmailSenderService eingerichtet haben, k\u00f6nnen Sie ihn \u00fcberall dort verwenden, wo Sie E-Mails programmatisch von Ihrem Plugin aus senden m\u00fcssen. Zum Beispiel in einem Controller:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ YourPluginName\/src\/Controller\/MyCustomController.php\n\nuse Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController;\nuse Symfony\\Component\\HttpFoundation\\Response;\nuse Symfony\\Component\\Routing\\Annotation\\Route;\n\nclass MyCustomController extends AbstractController\n{\n    \/**\n     * @Route(\"\/send_email\", name=\"send_email_route\")\n     *\/\n    public function sendEmail(EmailSenderService $emailSenderService): Response\n    {\n        $recipientEmail = 'recipient@example.com';\n        $templateId = 'your_template_id'; \/\/ Replace with the actual template ID you configured\n        $senderEmail = 'sender@example.com';\n        $senderName = 'Your Sender Name';\n        $data = &#91;\n            'some_variable' =&gt; 'Hello, this is a test email!',\n            \/\/ Add any other variables your email template might need\n        ];\n\n        \/\/ Call the EmailSenderService to send the email\n        $emailSenderService-&gt;sendEmail($recipientEmail, $templateId, $senderEmail, $senderName, $data);\n\n        return new Response('Email sent successfully!');\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>Mit dieser Einrichtung wird bei jedem Zugriff auf die send_email-Route in Ihrem Shopware-Schaufenster oder Backend die E-Mail unter Verwendung der konfigurierten Vorlage und Variablen gesendet.<\/p>\n\n\n\n<p>Denken Sie daran, die Platzhalter und Variablen an Ihren speziellen Anwendungsfall anzupassen, und stellen Sie sicher, dass Sie alle m\u00f6glichen Fehler oder zus\u00e4tzlichen Konfigurationen entsprechend Ihren Anforderungen behandeln.<\/p>\n\n\n\n<p>Bitte beachten Sie, dass Shopware 6 Aktualisierungen und \u00c4nderungen erhalten kann. Es ist daher ratsam, die offizielle Dokumentation auf \u00c4nderungen in Bezug auf den E-Mail-Versand in Shopware 6 zu \u00fcberpr\u00fcfen.<\/p>\n\n\n\n<p><strong>Bitte kontaktieren Sie uns unter <strong><a href=\"mailto:manish@bay20.com\">manish@bay20.com<\/a><\/strong> oder rufen Sie uns unter <a href=\"https:\/\/api.whatsapp.com\/send?phone=+918800519180&amp;text=Hi, I contacted you through your website.\" title=\"+91-8800519180\">+91-8800519180<\/a> an, wenn Sie Unterst\u00fctzung f\u00fcr Shopware 6 ben\u00f6tigen. Sie k\u00f6nnen auch die <strong><a href=\"https:\/\/www.bay20.com\/de\/shopware-entwicklungsunternehmen\/\" title=\"Shopware 6 development\">Shopware 6 <strong>Entwicklungsseite<\/strong><\/a><\/strong> besuchen, um die von uns angebotenen Dienstleistungen zu \u00fcberpr\u00fcfen.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sending emails programmatically from Shopware 6 can be achieved using the Shopware-provided services and components. To do this, you&#8217;ll need to create a custom plugin and utilize the Shopware Email Service to send emails. Here&#8217;s a step-by-step guide to help you accomplish this<\/p>\n","protected":false},"author":30,"featured_media":13742,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[78,115,91],"tags":[],"class_list":["post-13737","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-shopware","category-shopware-6","category-shopware-6-anleitungen"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/posts\/13737","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/users\/30"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/comments?post=13737"}],"version-history":[{"count":6,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/posts\/13737\/revisions"}],"predecessor-version":[{"id":17038,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/posts\/13737\/revisions\/17038"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/media\/13742"}],"wp:attachment":[{"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/media?parent=13737"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/categories?post=13737"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/tags?post=13737"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}