Creating the newsletter
If you have a look at the FlexForm Documenation about using the email function, you can see that you can create a page in your wiki (any page) and tell FlexForm to use that page to send one or more emails. So I have create a page called "FlexForm mail template" with the following contents:
%_to=info@wikibase.nl%
%_bcc={{#ask:[[Class::User]][[End of contract::False]] |mainlabel=- |?Email= |link=none |sep=,}}%
%_subject=Latest how-to's from our website%
%_from=info@wikibase.nl%
%_header=Mail_header_marijn%
<h3>Newsletter: 5 most recent How To's</h3>
{{#ask:[[Class::How-to]][[DevOps:+]]
|?Owner name=
|?Modification date=
|sort=Modification date
|order=desc
|limit=5
}}
The first 5 lines are well documented at the FlexForm Docs and they are pretty straightforward.
The only nice addition is the Semantic MediaWiki Ask query to get all emails from my colleagues, that still have a contract with our company, as a comma separated list.
The header for the email is set to a page called Mail_header_marijn, were I have a Widget that shows an image of my colleague Marijn. We use a Widget, so that we get correct HTML to use in our email. Source of the mail header page :
<div>{{#widget:Image |src=<full url to>/Marijn_look.png }}<hr style="margin:0;"></div>
And it looks like this:
For the body of our email there is another SMW Ask query to get all the lastest How To's from our website.
If I view the FlexForm mail template page it looks like this (I removed the email addresses from all my colleagues to prevent bot spams) :
The Header page will be merged once the email is send and we could use a Footer page as well, but we are ok for now.
Sending the newsletter
We are done setting up the newsletter and we can send it two ways. One is manually, by creating a simple FlexForm form with a button to send the emails. Or we can use e.g. a Python script or PHP script to call the MediaWiki API using a cronjob, so that we could send the Newsletter automatically every x days or x weeks.
Lets first quickly start create the manual way
<form action="email" messageonsuccess="Newsletter has been send">
<_email template="FlexForm_mail_template" />
<input type="submit" value="Send latest How-to's newsletter" />
</form>
This just looks like a button with the text "Send latest How-to's newsletter".
If you click the button, the emails will be send.
Using the MediaWiki API
Have a look at the documentation using the FlexForm Bot api here.
It needs:
- action = FlexFormBot
- trigger = email
- title = FlexForm mail template
- token = <your csrf token>
Once you send that to the API, FlexForm will send the emails.
In our email template we fill the BCC argument with the SMW Ask Query to get all email addresses from my colleagues. We could also remove that in the template and send the emails together with the API call, so your Python or PHP script will supply the email addresses.
You would then call the api like this :
- action = FlexFormBot
- trigger = email
- title = FlexForm mail template
- token = <your csrf token>
- data = <comma separated list of email addresses>
This way you could send emails in batches if you have a lot of recipients.
Now we have created a pretty simple email, but you could put the SMW query result through a template and make a really fancy HTML email.
For our example the mail looks like this :
Nothing holds you back to create your own email newsletter now!
If you have question or needs some help, there are various ways of contacting us, but for FlexForm support using Discord or Element click here
|