How to urgently send emails?

I am currently studying Drupal email features such as drupal_mail and hook_mail, and hook_mail_alter, and before that I have a problem when I need to be able to send emails with delivery delay. For example, a notification about the registration of an event, which should wait an hour after the event, was registered by the user. And this email has user-specific data, so it can't be just a general email template ...

I use the MailQ module, mainly for its logging capabilities, but I wonder if it (or something else) can change to add a custom delay function?

Any ideas?

========================

Some additional thoughts:

There are 2 modules in D6 that are useful for email queues, MailQ and Job queue (in the Nikita list below). Both of them have the functionality of the mail queue, which can be very useful, and both have different approaches, strengths and weaknesses - from a quick study. EG: MailQ has an excellent logging function, with a very useful admin interface for working with mail categories such as queued, send, send, failure, etc. And you can set how many emails will be released with each cron launch.

However, although the Queue task does not have these categories and log archiving, as far as I can tell, this allows you to prioritize different tasks, which can be very useful if you use different types of email at the same time, such as a confirmation contact, confirmation of event registration, and "invite a friend" emails.

Thus, my idea of ​​an ideal queue will include both of these modules (they don't get along very well) with an additional delay function for each type of job.

But writing such a thing is possible far beyond my meager talents, so I just need to write a small user module that is activated by cron, and this will look for marked contacts with a date of creation of at least an hour in the past and find a way to record relevant information directly in MailQ DB table

There seems to be some collision when I have both my new function called by cron and the MailQ function launched by the same cron run, so I'm trying to figure out how to prioritize cron MailQ over my function, so that my function will add AFTER MailQ table data.

+4
source share
1 answer

This is not the most elegant solution, but I did something in D6 before I knew transactional email services with hook_mail_alter, where I loaded the email parameters in the database table, set the message value to zero so it did not send after and then later the cron job running every 5 minutes will check the table and send a couple of messages at a time if they were expecting. When it is sent, I flipped the status for sending. You will receive a watchdog error informing you that the message has not been sent.

But with this method, you can either call something like Mailgun / Mandrill and send the scheduled email in the hook, or put it in the database table with a timestamp field like StrToTime ("+ 2 weeks"), and then have cron set a check on the table every x minutes and send when the timestamp conditions are met. hook_mail_alter provides a field for identifying the message, so you can have a switch that will only catch certain emails if you want.

If you like custom modules, take a look at the Mandrill module. This is probably a more elegant Drupal email solution than what I described above.

0
source

Source: https://habr.com/ru/post/1305406/


All Articles