Mail API with ability to group messages to a sender by delivery time

By : Shreeni
Source: Stackoverflow.com
Question!

For our product we need to be able to schedule email messages for a recipient. Our product also wants to ensure that the recipient doesn't get spammed by too many messages. So, we are looking for an API that allows our product to schedule the messages over to the API and if the API finds more than one message scheduled for the same time, then it combines them in a reasonably intelligent manner.

Example, the product calls API with following requests:

  • to: [email protected], title: "You need to approve request 123" message: "XYZ", schedule: 2PM
  • to: [email protected], title: "You request for 234 has been approved" message: "PQR", schedule: 2PM

At 2PM, [email protected] receives the following:

  • title: "Messages from Product"
  • messages: <Combined message from title and message of the two above>

It seems that MailGun fits our general requirements except for this one requirement. Is there an API that solves this? If not, how do others solve it?

By : Shreeni


Answers

I doubt that you will find any API/library with this functionality.

Combining messages "in a reasonably intelligent manner" will prove to be virtually impossible for a library knowing absolutely nothing about the nature of the content.

Using mailgun for sending mail is a very robust option - the throttling you mention is something you will have to add yourself.

If the messages are being pumped out at any rate you will need to introduce a waiting period to see if another message is coming. Knowing nothing about the rate of messages you will have to introduce delays if you have just sent a message (after waiting) when a new arrives.

If the system schedules messages for sending - eg. sending status messages at night/morning to users it might be a better approach to combine the messages before they are turned into actual e-mails.

By : mbanzon


You could create a simple database with two tables, "recipient" (name, e-mail adresss) and "message" (date_created, body, …). The relation of recipient to message is obviously 1:n.

Then you set up a cron job, collecting all messages that are older than, let's say, 5 hours; group them by recipient, wrap the messages into a nice template and pass them to the MTA.

Btw, I personally think that it's acceptable to send several e-mails within a short period of time – given that each e-mail is meaningful and self-contained. It is very nice of you to try reducing e-mail traffic, but in most cases, people won't mind, and they'll appreciate the instant notification.

By : lxg


This video can help you solving your question :)
By: admin