Documentation / Tutorials / Generic

How to send the bulk mail

/ Generic / How to send the bulk mail

We are sending bulk email and notification to the many profiles at a time [we don’t have mail scheduling on specific date].


  1. DB – Table: mailing_queue
    Columns: id, stamp, candidate_id, name, email, job_count, job_ids, notification_template, status
  2. Service: notification_service (module: send)
    Note: Notification service already registered in our system
  3. Service: common (module: send-notification)
  4. App: Any app
    Module: site-notification
  5. CPT: Notification Template (post_type > slug: notification_tpl)
  6. Create a new HTML template in Notification Template

Your app > module: site-notification > template: main
Code will call service [common.send-notification args=”” set=”template.result” … /] with the parameter “args”  (array with keys: email, name, mail_template and email_template specific extra parameters)

Step #1:

Create a table of mailing_queue


Step #2:

Create a service name it “common” (if not exists) – Create a module name: send-notifications

Put this code in send-notifications module:

Note: Notification service already registered in our system


Step #3:

Create a CPT (if not exists) : Notification Template

  1. post_type (slug): notification_tpl
  2. Label: Notification Template
  3. Post type should support “title”, “excerpt”, ”thumbnail”
  4. Public: False
  5. Create meta field: subject

Create a post (HTML template) for mail body in notification template CPT

We can add subject line here with the dynamic variables

Image: Subject line with dynamic variable and Email Template Slug

Example Slug: profile-status


Step #4:

Create a module in any app – Module Name: site-notificationadd created email template slug in the code

Code: (call separately or using cron)


Note: Template: Same name as email template slug (Image: Email Template Slug)

[templates.add profile-status]

/* Your code here based on the Array template.args values (this contains all the column values from mailing_queue table) Dump this variable so you will see that it contains all the values added in the mailing queue */
Example Code:

/* Mail sending code, default code, do not edit */
[common.send-notifications args={template.args} o.set=template.email_res /]


Step #5:

Insert data in to the mailing_queue and run the send-notification module. Two ways to do this

  1. Create a module and write logic to add the data in the mailing queue.
  2. Insert query result into the mailing_queue table using: INSERT INTO mailing_queue SELECT * FROM…..

Example query:

Table to table insertion from DB (All active profiles)

Step #6:

Add email ids to the mailing_queue table to send the mails 

Common Mistake: (Step#2 comes before Step#3, because send-notification runs using the cron, if we haven’t added the template in site-notification then it may try to call the template that does not exist. This will result in the Fatal error, avoid this error otherwise cron will not work)




4 Steps:

  1. Create a table (mailing_queue)
  2. Create a service of send notifications
  3. Create  an email HTML template in Notification Template (CPT)
  4. Create a module of send-notification in any app, and add template in this module (which is name of email HTML template name) 
  5. After done! all above things you need to run cron.


Cron will send the emails (Usual cron run time is 30 mins)

Cron base query:
SELECT * FROM mailing_queue WHERE status = ‘pending’ LIMIT 200


Improvement in mail notification:

  1. Schedule emails to send on the specific date
Most Popular

Leave a Reply

Your email address will not be published. Required fields are marked *