Right now it is impossible for contrib modules to provide additional settings for Swift. If there would be an alter hook, that is invoked before sending the email, contrib modules can provide their settings and apply them in the alter hook.

Patch will follow.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jelle_S’s picture

Status: Active » Needs review
FileSize
2.49 KB

Patch is attached.

Jelle_S’s picture

FileSize
2.48 KB

Fixed typos in readme.

B-Prod’s picture

Status: Needs review » Reviewed & tested by the community

This patch is OK.

Note that, as specified in the issue properties, it does not apply to the current release, but only to the DEV version. But the parts of the patch that does not apply are related to the README.txt file, so the patch can be used on the current release for those who need it.

sbrattla’s picture

Assigned: Unassigned » sbrattla
Status: Reviewed & tested by the community » Fixed

Applied patch to 7.x-1.x-dev. Thanks!

sbrattla’s picture

Status: Fixed » Closed (fixed)
webflo’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Status: Closed (fixed) » Patch (to be ported)
quadbyte’s picture

Status: Patch (to be ported) » Needs review
FileSize
2.43 KB

Here is my port for D8. I have added third parameter to the alter hook : $message which holds the original drupal message array, which may be useful to pass additional data to the hook.

Status: Needs review » Needs work

The last submitted patch, 7: swiftmailer-alter-hook-d8-2321215.patch, failed testing.

quadbyte’s picture

fixing patch carriage return.

webflo’s picture

+++ b/src/Plugin/Mail/SwiftMailer.php
@@ -358,6 +358,9 @@ public function mail(array $message) {
+      \Drupal::moduleHandler()->invokeAll('swiftmailer_alter', [&$mailer, &$m, $message]);

We should inject the module handler.

jcisio’s picture

Title: Provide an alter hook before sending the email. » Provide an alter hook before sending the email
Assigned: sbrattla » Unassigned
Status: Needs work » Needs review
FileSize
2.49 KB
705 bytes

Fix #10. I've changed the comment a little and remove the reference to the objects, which usually are not necessary and to keep it on par with D7.

webflo’s picture

Status: Needs review » Needs work

Patch no longer applies.

+++ b/src/Plugin/Mail/SwiftMailer.php
@@ -353,6 +353,9 @@ class SwiftMailer implements MailInterface, ContainerFactoryPluginInterface {
+      $this->moduleHandler->invokeAll('swiftmailer_alter', [$mailer, $m, $message]);

Isn't it possible to user \Drupal\Core\Extension\ModuleHandlerInterface::alter?

webflo’s picture

Status: Needs work » Needs review
FileSize
2 KB
webflo’s picture

webflo’s picture

+++ b/src/Plugin/Mail/SwiftMailer.php
@@ -61,6 +62,11 @@ class SwiftMailer implements MailInterface, ContainerFactoryPluginInterface {
+  protected $mailer;

unused property.

webflo’s picture

tstoeckler’s picture

  1. +++ b/src/Plugin/Mail/SwiftMailer.php
    @@ -384,9 +385,17 @@ class SwiftMailer implements MailInterface, ContainerFactoryPluginInterface {
    +            $mailer = Swift_Mailer::newInstance($transport);
    

    This happens in all cases, so I think it can just be moved to after the switch.

  2. +++ b/swiftmailer.api.php
    @@ -0,0 +1,31 @@
    +  $swiftMessage->setReadReceiptTo('your@address.com');
    

    The $addresses parameter is type-hinted as an array, so maybe put the address in an array.

webflo’s picture

tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me, thanks.

The last submitted patch, 11: 2321215-swiftmailer_alter-11.patch, failed testing. View results

The last submitted patch, 11: 2321215-swiftmailer_alter-11-interdiff.diff, failed testing. View results

  • webflo committed 2d6c87f on 8.x-1.x
    Issue #2321215 by webflo, Jelle_S, quadbyte, jcisio, sbrattla,...
webflo’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.