Skip to main content
added 128 characters in body
Source Link

I'm implementing a cron job that should send a notification email to all users that meet a certain criterion. I created a Service implementing the CronInterface and hook_cron calls this service's run() method. This queries for the users that need notification. I want to loop over these user and send emails to them. These emails should contain a default message and they should be greeted with their name.

The system already uses the "Drupal Symfony Mailer". Everything in the documentation seems to migrate configurations from other implmentations.

I tried implementing a Plugin extending EmailBuilderBase with:

@EmailBuilder(
  id = "notification",
  sub_types = { "update" = @Translation("Update") },
  common_adjusters = {"email_subject", "email_body"},
)

My expectation was that I will be able to

  • add a new policy on the configuration page that belongs to this class
  • provide my notification text, using a token for the user name
  • send the email via Drupal::service('email_factory')->sendTypedEmail('notification', 'update', $user);

This doesn't work. I can't create a policy matching my Builder. The dropdown menus on policy creation don't offer options for "notification" and "update" for the type and sub-type selection.

How do I create the policy that allows me to send my email via the method call above without writing a deprecated version that gets migrated?

I'm implementing a cron job that should send a notification email to all users that meet a certain criterion. I created a Service implementing the CronInterface and hook_cron calls this service's run() method. This queries for the users that need notification. I want to loop over these user and send emails to them. These emails should contain a default message and they should be greeted with their name.

The system already uses the "Drupal Symfony Mailer". Everything in the documentation seems to migrate configurations from other implmentations.

I tried implementing a Plugin extending EmailBuilderBase with:

@EmailBuilder(
  id = "notification",
  sub_types = { "update" = @Translation("Update") },
  common_adjusters = {"email_subject", "email_body"},
)

My expectation was that I will be able to

  • add a new policy on the configuration page that belongs to this class
  • provide my notification text, using a token for the user name
  • send the email via Drupal::service('email_factory')->sendTypedEmail('notification', 'update', $user);

This doesn't work. I can't create a policy matching my Builder.

How do I create the policy that allows me to send my email via the method call above without writing a deprecated version that gets migrated?

I'm implementing a cron job that should send a notification email to all users that meet a certain criterion. I created a Service implementing the CronInterface and hook_cron calls this service's run() method. This queries for the users that need notification. I want to loop over these user and send emails to them. These emails should contain a default message and they should be greeted with their name.

The system already uses the "Drupal Symfony Mailer". Everything in the documentation seems to migrate configurations from other implmentations.

I tried implementing a Plugin extending EmailBuilderBase with:

@EmailBuilder(
  id = "notification",
  sub_types = { "update" = @Translation("Update") },
  common_adjusters = {"email_subject", "email_body"},
)

My expectation was that I will be able to

  • add a new policy on the configuration page that belongs to this class
  • provide my notification text, using a token for the user name
  • send the email via Drupal::service('email_factory')->sendTypedEmail('notification', 'update', $user);

This doesn't work. I can't create a policy matching my Builder. The dropdown menus on policy creation don't offer options for "notification" and "update" for the type and sub-type selection.

How do I create the policy that allows me to send my email via the method call above without writing a deprecated version that gets migrated?

Source Link

How do I implement email dispatch with Drupal Symfony Mailer from scratch?

I'm implementing a cron job that should send a notification email to all users that meet a certain criterion. I created a Service implementing the CronInterface and hook_cron calls this service's run() method. This queries for the users that need notification. I want to loop over these user and send emails to them. These emails should contain a default message and they should be greeted with their name.

The system already uses the "Drupal Symfony Mailer". Everything in the documentation seems to migrate configurations from other implmentations.

I tried implementing a Plugin extending EmailBuilderBase with:

@EmailBuilder(
  id = "notification",
  sub_types = { "update" = @Translation("Update") },
  common_adjusters = {"email_subject", "email_body"},
)

My expectation was that I will be able to

  • add a new policy on the configuration page that belongs to this class
  • provide my notification text, using a token for the user name
  • send the email via Drupal::service('email_factory')->sendTypedEmail('notification', 'update', $user);

This doesn't work. I can't create a policy matching my Builder.

How do I create the policy that allows me to send my email via the method call above without writing a deprecated version that gets migrated?