Automatically send eMail when new resource is published

Hey guys,

is there a ready to use solution for an automated eMail notification system for frontend users (not backend users) which sends an eMail each time a new resource is published?

Usecase: I am planning to offer a “subscribe to this category” form on the frontend, in which a user can type his eMail. The categories are just parent resources. Each time a child resource is published, the subscribers should receive an eMail which states “dear user, we have new content in the category you like”.

I don’t want to use third party tools.

For the subscription part: custom db table, formit2db (i only need to fetch the eMail + parent ID of viewed article (=the “category”), double opt in via email with “activation” of the subscriber in the db, custom CMP to manage the subscribers. (Other / better ideas welcome)

For the automated eMail sending process: I need to fetch the subscribers’ eMail addresses from my custom db - according to the parent ID (the “category” they are interested in) of each new published resource - and then automatically send an eMail to them.

What is the best practice to sending that eMail? Use Formit in a plugin? ModMail?

Please note: I don’t want the eMail to get send each time a resource is updated - only when it is published for the first time.

Pretty sure Bob’s Subscribe extra was built precisely for the use case you described. The only thing it’s all native users/signups so it wont fetch emails from a custom database I think.

I’ve not personally used it, but am on the receiving end of that for Bob’s site and that seems to work as expected. :wink:

Not quite exactly what the OP wants. The send is manual, though it takes just a few clicks. I publish a some pages that aren’t worth notifying people about and I can also send subscribers messages that have nothing to do with publication.

It’s actually Notify that sends things out (in conjunction with Subscribe). It sends the description and/or summary (based on the Tpl chunk), but you can edit it manually before the send. It also (optionally) sends a tweet.

Subscribers have control over which topics they follow and the emails can be sent to user group(s) and filtered by their personal list of topics.

Users can set and reset their topic list, or unsubscribe, from a link in each message.

1 Like

Thank you for your responses and especially for the summary, Bob. The part about setting and unsetting the topic list I find very interesting, although I am still thinking about how the process could be automated.

Is there a system event that gets triggered when a resource is created (and only then - so just once and not again i.e. when the same resource gets edited and saved later) and could be used to trigger a custom plugin?

If not: could I use OnBeforeDocFormSave to check if the resource has an ID already (or in other words: exists)? If so nothing should be done, otherwise the mailing should be triggered?

What about the mailing part? Could Formit be used for that as I already need it?

FormIt just uses the built in mail service. So there is no need to use FormIt. Just use the mail service in your code according to the documentation.

1 Like

OnDocPublished, but see the limitations on that page. I’m not sure they’re still true.

1 Like

Thank you @halftrainedharry, the mail service works perfectly fine.

@bobray unfortunately the limitation is true: the event only gets fired when a resource gets published via the context menu in the resource tree.

How about this: custom db table in which i log the amount a resource got published and its ID. Then onDocFormSave I check, if the current resource’s published-amount is > 1, otherwise fire my eMail. Logic? Other ideas?

Checking the published field on save that way would send an email every time a published resource was saved, but your plugin could set one of the unused modResource fields to indicate that a notification had already been sent. One of these fields might be good if they’re still there: donthit, privateweb, privatemgr. All three are boolean fields that can contain 1 or 0, and AFAIK they’re unused.

Another way to go: a long time ago, I wrote an extra called ActivationEmail with a plugin that did something very similar to what you want, but with user activation rather than resource publication.

In onBeforeUserSave, it checked the active field in the DB for that user then checked the value in the user object being saved. If the DB field was 0, the field for the object being saved was 1, it sent the email.

You should be able to do the same thing in OnBeforeDocFormSave, comparing the published field in the DB and the $resource variable.

The plugin code is here.

Thank you for your two solutions and your plugin code, Bob. I will dive into that.
Those three fields are still there, yes (2.8.1).