9

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: test@test.com, title: "You need to approve request 123" message: "XYZ", schedule: 2PM
  • to: test@test.com, title: "You request for 234 has been approved" message: "PQR", schedule: 2PM

At 2PM, test@test.com 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?

Antony
  • 14,900
  • 10
  • 46
  • 74
Shreeni
  • 3,222
  • 7
  • 27
  • 39

2 Answers2

2

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.

lxg
  • 12,375
  • 12
  • 51
  • 73
0

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.

Michael Banzon
  • 4,879
  • 1
  • 26
  • 28
  • That is perhaps the case, but then the management of throttling or combining makes the Mail Infrastructure quite heavy on the product side. I was hoping that this problem was prevalent enough for MailGun (and others like them) to have solved it.. – Shreeni Jun 09 '14 at 09:58