Sending Mail Using Mail Merge

Hi WapplerFreaks..!

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.

Has anyone else out there done something better?

Thinking maybe a custom formatter or module that will parse() the text to include variables enclosed in {}.

Not sure if it will work but will take a look but wont be until later today. Guess it would be a really useful extension if it can be done

1 Like

I'm not really sure such formatter/module would provide any significant speed benefit

There's still a Repeat step and there's still a Database Query step, the string replace formatter performance is negligible in my opinion

I was thinking about just chaining .replace formatters, like:

emailStr.replace('[[Company]]', '456').replace('[[name]]', 'Tom')

Where '456' and 'Tom' would be replaced by variable names, whose data is coming from a database query

I'm not sure you can get it more efficient

1 Like

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)

1 Like

@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.

I agree about the flexibility, matching via field names could very well be a little quicker on the server side.

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

1 Like

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

1 Like

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.

1 Like

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.

1 Like

Looking like this is possible as a custom module via this, just need a bit more time

image

1 Like

Should be publishing a merge document to query server component tomorrow.
Have it working, just cleaning up and tweaking.

Allows embedded field names like this

Hi, [name]  - your record is number is [people_id]

and a query such as this with output:

{ people_id: 1, name: 'Brian English' }

are merged to output:

Hi, Brian English - your record number is 1

All field mapping is done automatically by matching [tag] to fieldname.
Can be used singly or inside a repeat.

text can be $_ variable, dynamic value (e.g. summernote output) or static

2 Likes

That sounds amazing Brian. Great also to have the choice of single or repeat, as I can see both being used.

I use mail merge all the time and I’m sure others do too so this is yet another cracking Wappler extension.

Also, I think the embedded field names are where the biggest time saving will be

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)

1 Like