I have an mailer page I use to send emails to less than 2000 users per mailout, it works perfectly and has error checking, sockets etc etc. It sends a preformatted personalised message that has been created server side, each message has information in it that is unique to each user - here it is on the admin side running away quietly doing its thing.
I'd like to do something similar for the backend admin side, Id like to send mail merged messages containing personalised data taken from a companies database (company name, recipient name, country etc).
The email would be compiled by a site admin on the front end (so secure behind a login), Id like it to look something like this:
Hi [[Recipient]],
Just a quick email to let you know that [[Company]] needs to log in to update their country info, we currently have you listed in [[Country]] .......
So what I was planning on doing was POSTing this to the server, then doing a replace of [[Recipient]] with the acutal value of the company taken from a server side query during the repeat for the mail.
However, this doesn't look like an efficient approach so I thought I would check to see if there's a better way to do it.
But passing the query and the text to a .js script via a custom module or function's HJSON and allowing .js to parse() them would also be highly efficient but also infinitely more flexible if matching is one via field names and therefore automatic rather than being .replace() individually and programmatically. (if i can make it work of course)
@Apple@Hyperbytes I think both answers are workable, regarding efficiency I suppose it boils down to how much faster(?) Wappler is at processing the string manipulation internally using a custom formatter compared to a standard string replace function.
As I'm looking at a max of 2000 records any savings would soon mount up, if it works fine, I have another potential mailout of up to 5 - 10k.
If you use an e-mail sending service with API, they might have some functionality to bulk send e-mail instead of doing 2000 SMTP connections. They might also have template functionality, but might not be useful in your particular case
Great suggestion there, I already use SendGrid but would prefer to keep these ones in house if I can.
Additionally, I've got an excellent but old bit of software called WorldMerge which is fantastic, but relies on a desktop and is not connected in any way to the server.
As the Wappler .replace() function is an interface to the .js replace() method then i doubt there will be any significant difference when called in a custom module as the HJSON defined interface simply passes the parameter directly to the .js module as a function parameter
Please remember that hosting providers set email restrictions. It may be an idea to send the emails in batches with a waiting period before the next batch. This will need to be checked with the hosting provider's restrictions.
PS: I used to use PowerMessenger that had the batching feature incorporated.
Thanks for that Ben. It’s our own server so we have no limits. Word merge does something similar to powermessenger too. Both great tools but I need this to be server based.
Yes, i always thought mailmerge was a big omission from wappler. Cant believe how easy it was, only 9 lines of .js (no error checking implemented yet though)