Jump to content

Best approach for mailing users


heldercervantes
 Share

Recommended Posts

Hi guys.

I'm currently developing a volunteering board solution. Basically users register saying what are their areas of interest and how they are available for helping, and then there's a "job board" of sorts that lists where help is needed.

So I'm doing a simple user registration form, creating users with a specific role. And when I publish a new help request, I want the admin to be able to select from the options of the areas of interest and availability fields, and that should fire an email alert to all corresponding users. This process should be as dummy-proof and straightforward as possible.

Any suggestions on how to approach something like this?

Link to comment
Share on other sites

I would use a Pages::published hook for that.

Assuming that the "help request" is a single item (I'll call it job in my example) on your "job board" and that both users and jobs have a page reference field "interests" that links to the area of interests, you can attach that published hook and everytime a job is published, those emails will get send. Dummy code:

wire()->addHookAfter('Pages::published', function(HookEvent $event) {

  $page = $event->arguments(0);
  if($page->template !== 'job') return;

  // build selector value for interests, e.g. 1234|3456|5678
  $interests = implode('|', $page->interests->explode('id'));

  // get users who are interested in this job, assuming the template for users is 'applicant'
  $interestedUsers = wire('pages')->find("template=applicant, interests={$interests}");
  // either send emails directly
  foreach ($interestedUsers as $u) {
    // logic for sending emails 
  }
  // display send result status message
  wire()->message('Notifications sent', 'success');

  // or create a page for job-notifications and redirect there
});

 Sending emails directly from this hook will take some time until the admin user gets a message displayed. So this might not be optimal.

As an alternative you could create a job-notification page and redirect the admin there. On that page you can list the interests and intersted users and a sent status as well as a send/resend button and handle the sending there. With these separate notification pages available in the system you could build a custom Lister for an overview which makes it more convenient to interact with the notification system, see sent statuses etc.

  • Like 2
Link to comment
Share on other sites

7 hours ago, gebeer said:

 Sending emails directly from this hook will take some time until the admin user gets a message displayed. So this might not be optimal.

This is one of my worries. Right now we have a universe of 600 potential users, so we might be talking about hundreds of emails. Not even sure if the hosting provider will be happy with it.

In terms of UI I'm thinking of having a checkbox at the end of the page for "Send email alerts on save", which would be used in the hook. And then maybe tie this with ProMailer for throttled sending, handling unsubscribe and all those nice things it does. But I haven't tried it yet so idk if there are any cons.

Link to comment
Share on other sites

The problem has two dimensions

1) ProcessWire

You need to execute the long running task somehow in the background. There are many ways how to do that. The simplest solution could be a cronjob that runs every minute, bootstraps PW and executes all open tasks. If your task can run longer than 1 minute then you need to implement some kind of locking mechanism or as an ugly alternative just run the task every 5 minutes or so. We also have WireQueue that could help maybe.

2) Sending Mails

If you are on a shared host I doubt that it would be a good idea to send emails from there. Either the hoster will have limits in place or, if not, mails will likely not land in the users inbox because chances are high that the hosters IP is blacklisted somewhere.

If you have a dedicated VPS you should be fine, but I have no experience in how many emails you can send from one single VPS realistically and I'd be very happy to get some numbers if anybody else has experience in that area! 🙂 

Link to comment
Share on other sites

@heldercervantes Do you have an estimate of the number of emails you expect to send in a month?  Also, does the organisation have any budget for sending?  If it does, then one of the more reputable transactional email services would be a good place to look.  I've had excellent service from Postmark, at a reasonable price (~$15/10k emails) and their deliverability is very good and very fast.

Link to comment
Share on other sites

On 4/21/2023 at 10:51 PM, netcarver said:

Do you have an estimate of the number of emails you expect to send in a month?

Right now, just one or two hundred. I have a universe of 600 potential users, and I expect about 100 to enroll. These users will get email notifications selectively if a gig is posted that matches their preferences. But this is intended to grow and there will be an effort to increase the user base.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...