Mail Blocker usage? How?

New feature on RainLab.User is really perfect, because before any kind of email is sent to user, it is check, if user has blocked specific type of template known as mail template. But, unfortunately, for now, there are only one checkbox in User profile, and, of course, only on backend.

Block all outgoing communication

This feature allows admins, to block every outgoing email to be sent, but, in real world, there may be something more precise, right? For example, different types of emails, like newsletters, system messages, hot topic alerts, or what came in your mind.

Not easy, but still possieble

For client of mine, last days i found out, how this can be implemented, because there are multiple choices and paths to achieve specific results. Small peek-a-boo from user profile settings for notifications.

As you can see, on this image are multiple “switches” belonging to specific type of newsletter. Because i prepared sending newsletters from custom made plugin, there are still only 5 different email templates, then i can block specific template.

Deep look into it

First switch is main “Block all outgoing communication” like on backend, but managable with user. This switch calls MailBlocker::blockAll(Auth::getUser()). On background its create a wildcard block, then, each time, when is used Mail::send … User plugin listenning for mailer.prepareSend event. Then is checked MailBlocker::filterMessage($view, $message); what means, there is sent and template code and whole message object as is.

To separate correct blocking for specific types of newsletters, there must be specific template code. From default october funcionality, each email based on mail templates, is separated email, right, then you need to create for example 3 or 5 email templates. Mine was newsletter.empty as default, for each occasion, then newsletter.newCourse, newsletter.saleAlert, 'newsletter.feedbackandsystem`.

On plugin admin selects specific type of newsletter and fill out specific fields for selected kind of newsletter. For example, when is saleAlert, then admin can pick product to be promoted and template was prepared to build whole body. When admin uses empty template, then whole newsletter body is managed by custom templates. On this i will be glad, when snippets will work, but, unfortunately, not.

Plugin in action can see https://youtu.be/WwGkYIvrNEY …

Final words

It will be perfect, if there is some kind of easy way, how to manage this little things, but, from perspective of octobercms mail templates and funcionality right now, if there will be a list based on email templates, this can be really big NO. When each newsletter or mail is sent from mail templates, and some developers uses this without any other way… uff.

But, of course… Share some “love” and fire some comments and toughts.

Thanks

Hey @snipi !

MailBlocker is indeed a cool system. However, we removed it in User v3 and replaced it with UserPreference model because it was more generic.

You should consider making a mail blocker plugin and elaborating on these ideas!

so saaaad to read that … but, maybe for legacy purpose it may stay as is, or?
i had implemented UserPreference on new version of site

{{ user.getPreference('new_courses_notification') ? 'checked' : ''}} 

but this is a loooong way from “public” :smiley:

1 Like

Don’t be too sad. It is mostly the same thing, except it can be used for more than just blocking mail. A simple event can be used to convert preferences to blockers.