Problem/Motivation

Webform module is supported by LegacyEmailBuilder (Legacy mode) in Symfony Mailer Back-compatibility module.

However, if a webform has a custom reply-to address the final email has the sender email address as reply-to address.

Steps to reproduce

  1. Create a webform
  2. Add email handler
  3. Set a Reply-to email address
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

balis_m created an issue. See original summary.

balis_m’s picture

Status: Active » Needs review
adamps’s picture

Title: LegacyEmailBuilder: Webform reply-to is not working » Add EmailBuilder for Webform
Category: Bug report » Feature request
Status: Needs review » Needs work

This is currently documented as a restriction of Legacy mode.

I understand your motivation here, but I am reluctant. If we add this one field, then someone else will want another and so on perhaps without end. And the code we add will have restrictions - for example I expect that code will only work for a single reply-to address without a display name.

My preference would be to push forward adding more email builders in the Proxy mode, like you did for UserRegistrationPasswordEmailBuilder. The documentation link explains various advantages, and it is a stepping stone to a native implementation.

What do you think?

balis_m’s picture

Status: Needs work » Needs review

@AdamPS, at first, I thought that it could be better to do some fixes on LegacyMailBuilder, but I understand your motivation.

I've added the new WebformEmailBuilder to the existing merge request. Also, I've added an extra functionality to cancel the email sending.

adamps’s picture

Great thanks for your work here.

Also, I've added an extra functionality to cancel the email sending.

I absolutely agree this is a good idea. I have added an issue for it #3262457: Cancel email sending with an explanation of what I think is the right way to do it. Please can you take a look and see what you think?

I've added the new WebformEmailBuilder to the existing merge request.

Great thanks. I suggest we resolve the above issue first then revisit here.

One review comment I noticed in my first quick look: I think it should include a hook_mailer_bc_MODULE_alter() similar to symfony_mailer_bc_mailer_bc_contact_alter() that will set the entity. This would allow configuring policy specific to a single web form.

adamps’s picture

I would be very interested in your thoughts on #3262540: [META] Use Policy GUI even with back-compatibility please. Webform is a very good example, as almost all of the EmailBuilder duplicates Symfony Mailer policy.

balis_m’s picture

Your idea is good, but on each webform we can apply multiple email handlers with whole different settings. How could we implement that?

adamps’s picture

Status: Needs review » Needs work

Ah I see what you mean. I never used webform and didn't realise how complex the configuration is.

So the next step here is to integrate #3262457: Cancel email sending and apply the comment from #6.

adamps’s picture

FYI I have reconsidered on the matter of the legacy email builder if you are interested in that: #3262946: Add support for more headers on legacy emails

Of course let's still keep this new EmailBuilder in any case.

balis_m’s picture

Status: Needs work » Needs review

I have made the appropriate changes to skip the email sending.

One review comment I noticed in my first quick look: I think it should include a hook_mailer_bc_MODULE_alter() similar to symfony_mailer_bc_mailer_bc_contact_alter() that will set the entity. This would allow configuring policy specific to a single web form.

It is not necessary as users can add multiple email handlers (with different body, sender etc.) on each webform. Also, the webform_submission entity is not an instance of ConfigEntityInterface.

I have reconsidered on the matter of the legacy email builder

Great, I think that it will be really useful to include more headers.

adamps’s picture

Great thanks

It is not necessary as users can add multiple email handlers (with different body, sender etc.) on each webform. Also, the webform_submission entity is not an instance of ConfigEntityInterface.

I do think it will be useful to allow per-webform Symfony Mailer policy. It has functions not available in webform (transport, theme, skip sending, ...) and also some sites might prefer to keep the policy in a single place.

I'm not familiar with the code, however the entity I had in mind from a quick look was Drupal\webform\Entity\Webform. It's similarly for contact module: the entity is ContactForm rather that Message.

adamps’s picture

Status: Needs review » Needs work
balis_m’s picture

Status: Needs work » Needs review
StatusFileSize
new61.38 KB
new19.16 KB

I have made some of the suggested changes.

I understand your motivation, but I think that the approach that we have now is clear and more flexible.

We can add mailer policy for each webform email handler by adding an underscore-separated string with the webform id and the webform email handler id. In example, to override the webform email handler with id email_confirmation on webform with id contact, we add the value contact_email_confirmation to the syb_type textfield. (screenshots attached)

rajab natshah’s picture

Thank you, Balis and Adam for working on this new feature issue

Testing to apply the MR in a site ( with the back-compatibility module )
But I'm facing the following error, right after applying the 13.patch

The website encountered an unexpected error. Please try again later.

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "mailer_transport" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 143 of core/lib/Drupal/Core/Entity/EntityTypeManager.php).

Should this only work when the back-compatibility module is off?

balis_m’s picture

@AdamPS I have made some improvements.

Now, the webform sub-types are provided dynamically. Unfortunately, users have to clear all caches after adding/removing webforms/handlers.

Also, I have setted all the webform variables in the email template. So, from mailer policy, users can override the email body and subject too.

@Rajab Natshah This works when the back-compatibility module is on.

Could you please install the latest dev version, apply the patch https://git.drupalcode.org/project/symfony_mailer/-/merge_requests/13.diff, disable symfony_mailer/symfony_mailer_bc and enable them again?

adamps’s picture

Status: Needs review » Needs work

Great thanks for the updated patch. webform is a pretty complex example so it's a very useful testing ground for symfony mailer. I feel very comfortable with the direction this patch is heading - integrating with symfony mailer where possible yet also being pragmatic where needed.

Also, I have setted all the webform variables in the email template. So, from mailer policy, users can override the email body and subject too.

Great idea

Now, the webform sub-types are provided dynamically. Unfortunately, users have to clear all caches after adding/removing webforms/handlers.

I guess that might cause confusion. Perhaps we would ideally use the entity API to do it automatically.

Also see comments in the review. Many thanks.

adamps’s picture

OK, I think I've got a much better idea.

  • I raised #3271395: Re-use policy configuration with "pre-sets". As far as I understand it, this would be equivalent to email handlers, and it's a good idea.
  • Then we go back to the "natural" idea that the entity ID is the webform ID. It removes the need for extra code in symfony_mailer_bc_mailer_builder_info_alter().
  • Later on it should be possible to apply #3265253: Add policy listings to module entity/settings forms to webform.
  • The @todo comment at the top of WebformEmailBuilder can say to remove the concept of email handlers entirely. Also should use Email::appendBodyEntity() instead of setBody().

What do you think??

david.qdoscc’s picture

I hope you don't mind me suggesting that until this is fixed you add a fairly prominent warning on the project page explaining that there are currently compatibility issues with Webform (reply to, cc, bcc etc). Webform is one of the most widely installed contrib modules, and with the expectation that symfony mailer is a straightforward swap-out for swiftmailer, this issue is likely to catch a lot of people out.

adamps’s picture

the expectation that symfony mailer is a straightforward swap-out for swiftmailer,

Eventually yes. But this module is currently an alpha, and not ready for live use. I realise that people are using it anyway because swiftmailer is unsupported. Possibly many modules won't work, not just webform and there is already a documentation page dedicated to that linked from the project page. I've updated the project page generally to make this clearer.

adamps’s picture

Since #3262946: Add support for more headers on legacy emails Webform should work much better without this issue. Please can someone test? Currently requires the dev release.

This issue should stay open for the next level, an EmailBuilder will give significant advantages.

hchonov’s picture

However, if a webform has a custom reply-to address the final email has the sender email address as reply-to address.

I can confirm that this issue does not exist with the current alpha 10 release.

Grimreaper made their first commit to this issue’s fork.

grimreaper’s picture

Hi,

I am trying to send webform attachment with Symfony Mailer.

So I have created a new MR, rebased against last dev branch to test it.