When you're theming a Drupal Commerce site, you shouldn't forget to style the emails your store sends. The primary use case is the checkout completion email that includes the customer's receipt, but there may be others depending on your feature set and customizations (e.g. dunning emails for recurring subscriptions).
Commerce Core provides a basic, table based template that you'll want to either replace or at least ensure is styled by your theme to reflect your branding. (Find it in the order module's templates directory, commerce-order-receipt.html.twig.) However, without adding the capacity to properly send HTML email from your site, it's going to look like a jumbled mess in your customer's inbox.
We've long recommended Swift Mailer for formatting and sending HTML emails from Drupal Commerce. Symfony announced the project's deprecation late last year, recommending folks switch to using the 3 year old Symfony Mailer instead after they brought it up to full feature parity with the Swift Mailer library.
Fortunately, there's a module for that!
Drupal's Symfony Mailer module integrates the library and provides a "backwards compatibility" module that ensures the module can serve as a drop-in replacement for the old Mail System module the Swift Mailer module depended on. Making the switch in my local testing was as simple as:
- Uninstall the Swift Mailer module.
- Uninstall the Mail System module.
- Add the Symfony Mailer module to my project (using Composer).
- Install the Symfony Mailer and Symfony Mailer Back-compatibility modules.
- Define a transport type. (I develop locally with ddev, so I added an SMTP transport using 127.0.0.1 as the host, port 1025, and no username / password.)
- Make that your default transport.
And that's it! After taking the above steps, my email receipts showed up as properly formatted HTML emails. If you're also developing locally using ddev, remember you can review all email sent by your site in MailHog on port 8026 (i.e. by navigating to https://example.ddev.site:8026).
The Symfony Mailer module offers a variety of "policy" options you may need to review depending on how you've customized email on your site. You can use these policy options to alter properties of different emails, such as setting a custom reply-to address for your receipt emails.
The module is still in active development with only an alpha release, so make sure to test it fully in a development environment before deploying to production. Leave a comment with any tips you glean from your own implementation!
Comments
Submitted by jb (not verified) on Tue, 04/05/2022 - 08:03
security
you don`t have any security concerns using it?
Submitted by Ryan Szrama on Mon, 04/18/2022 - 19:13
In reply to security by jb (not verified)
(No subject)
(Bear in mind that even projects "covered" by the policy can still have security issues; it's just that there's a process by which the security team oversees disclosure and communication about vulnerabilities. Great question, though!)
Submitted by Eric Guerin (not verified) on Fri, 06/17/2022 - 19:00
Mail System still useful
Submitted by Michael Lechasseur (not verified) on Wed, 03/29/2023 - 18:58
drupalcommerce/commerce_base required swiftmailer
The site was created in Drupal 8 and the composer.json made reference to:
"drupalcommerce/commerce_base": "dev-8.x-1.x",
Despite making a "composer update drupalcommerce/commerce_base" the swiftmailer requirement was still included. But forcing an upgrade to commerce_base "9.x" added symphony mailer and removed swiftmail and mailsystem but the composer update broke my site because the modules hadn't been uninstalled from the UI.
I reinstalled swiftmail and mailsystem, then uninstalled from the Drupal UI, then removed with Composer.
That seems to have worked.
Submitted by Ryan Szrama on Wed, 05/31/2023 - 14:00
In reply to drupalcommerce/commerce_base required swiftmailer by Michael Lechasseur (not verified)
(No subject)
Add new comment