I have a post job content type. When an employer posts a job, all the registered users, basing on the job category (taxonomy), should receive an email about the posted job.

How should I implement this?


1 Answer 1


You'll have to write some code, essentially you need to hook in when Job node is created, find the users referencing to that taxonomy the Job has and then use the Mail service, something like (pseudo)

When a Job node is created

Get all user that has a reference to the created Node's taxonomy:

$job_tax_tid = $node->get('job_taxonomy')->target_id

Then find the users, perhaps by using a Entity Query:

$ids = \Drupal::entityQuery('user')
  ->condition('status', 1)
  ->condition('field_job_refs', $job_tax_tid)
$users = User::loadMultiple($ids);

To send mail programmatically, you need to use the MailManager: http://valuebound.com/resources/blog/how-to-send-mail-programmatically-drupal-8

Since there can be many users that needs to receive an email, you maybe want to use the Queue or Batch operations.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.