logo

MMBase tips

Sending mail to a group of users

tip #7 / Mon 4 Jan 2010 / André / 0 comments

Following up on my previous posts about mail I will now introduce you to spamming a group of users. Mailing several people at once is done by relating an email to a node - for example a groups node - with related users.

A group can have several forms: like for example an article with users that have subscribed themselves to be aknowledged of any comments. Or like the default implementation: a 'pools' node with related users.
If you wish to change the default 'pools' and 'people' nodetypes to something different you can do so by changing some properties in the email builder. The only requirement is that the related nodes representing the users should have a field with a valid email address specified in the property 'users-email-field'.

<properties>
<property name="groups-builder">pools</property>
<property name="users-builder">people</property>
<property name="users-email-field">email</property>
</properties>

Create an email, like in one of the previous tips.

<mm:createnode id="email_node" type="email">
<mm:setfield name="subject">Hi, I invite you all to...</mm:setfield>
<mm:setfield name="from"> you@domain.org </mm:setfield>
</mm:createnode>

Refer it to a group node which has has related user nodes with a field 'email'. You can to this for example when someone posts a comment and mail it to all users who subscribed.

<%-- relate the newly created email to a group --%>
<mm:node id="group_node" number="group_alias" />
<mm:createrelation source="email_node" destination="group_node" role="related" />

<%-- send the email --%>
<mm:node referid="new_email_node">
<mm:functioncontainer>
<mm:param name="type">oneshotkeep</mm:param>
<mm:function name="mail" />
</mm:functioncontainer>
</mm:node>

The mail is send immediately after it is related to the group node.
I choose 'oneshotkeep' since this keeps the email as a node in mmbase and can be used to build a mail archive.

0 comments

RSS feed

Tweet this article

Most mentioned links:

MMBase documentation
MMBase API
MMBase SVN
Bugtracker
MMBase Taglib reference
The reference for all tags mm