0

I'm aiming to send a post dated email through postmaster. I'm (successfully) sending out emails though a custom addon, by triggering a hook inside the custom addon and passing some data through the hook.

However, I'm trying to send out a post dated email in the same fashion and I'm not sure if it's the 'correct' way to do it.

Basically, I've set up a hook in postmaster, this is being triggered and it's also queuing the email in the exp_postmaster_queue table. In this table it's storing the to_name, the to_email and even a fully parsed message.

Now, when I trigger the ping url it removes the email from the queue and chucks it into the the mailbox - however the message fails to send as it's trying to send to the non parsed email variable (and the message also contains non-parsed variables) - {hook:participant_email}.

Does anyone know if sending a post dated email is possible through a hook, and if so how can I parse variables through?

The data seems like it's all in the queue table, so it must be reparsing (I started to pick the addon apart at which point I got a touch stuck).

Thanks

Dave

1 Answer 1

0

It looks like this was a bug occuring in the Postmaster addon when sending emails from the queue. The send_from_queue method is trying to reparse the hook template which is not working as there are no stored variables (email, to and variables in the template) in the row in exp_postmaster_queue. Instead, I believe it should be using the rendered message present in the column message.

I made and edit to the method send_from_queue method in the Postmaster_lib class - libraries/Postmaster_lib.php around line 456. Basically, I'm using the queue row data and passing that directly to the send method in the same class:

$parsed_object = $row;

I had to pass the hook settings through:

$parcel->settings = json_decode($parcel->settings);

And also a required property:

$row->post_date_specific = false;

And finally, copy the message over to the html_message property (for some reason the html and plain messages were not present in row):

$row->html_message = $row->message;

This is a bit hacky I know - I would open a pull request but a) I'm not sure if this actual cause of the issue, and b) I don't think the dev is supporting anymore.

Full code method here:

public function send_from_queue($row)
{

  if(!empty($row->parcel_id))
  {
    $parcel = $this->model->get_parcel($row->parcel_id);
    $parcel->entry = $this->model->get_entry($row->entry_id);

    $parcel->settings = json_decode($parcel->settings);
    $parsed_object = $this->parse($parcel);
  }

  if(!empty($row->hook_id))
  {
    $parcel = $this->model->get_hook($row->hook_id)->row();

    $parcel->settings = json_decode($parcel->settings);

    $row->post_date_specific = false;
    $row->html_message = $row->message;

    $parsed_object = $row;
  }

  $this->model->remove_from_queue($row->id);
  $this->send($parsed_object, $parcel, TRUE);

}

Hope this helps someone (most likely me)...

Your Answer

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

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