Table of Contents
(from example1.jsp) <!-- create the email node --> <mm:createnode id="mail1" type="email"> <mm:setfield name="from">Daniel <daniel@mmbase.org></mm:setfield> <mm:setfield name="to">daniel@mmbase.org</mm:setfield> <mm:setfield name="cc">michiel@mmbase.org,documentation@mmbase.org</mm:setfield> <mm:setfield name="subject">my first mmbase email !!</mm:setfield> <mm:setfield name="body">Just testing email</mm:setfield> <mm:function name="mail" /><!-- mail the email node --> </mm:createnode>
Here the Node is created and filled the with the fields we need, most of the normal headers can be set (to, from, reply-to, subject, cc, bcc, body), and even before it is commited, it is send with the 'mail' function on it. The mail function has one parameter 'type', which defaults to 'oneshot' (so it is not supplied here). The oneshot type means the email will be deleted once its mailed, for reasons you will find out in following examples its not deleted right away but only after the email expire time passed.
(from example2.jsp) <!-- create the email node --> <mm:createnode id="mail1" type="email"> <mm:setfield name="from">daniel@mmbase.org</mm:setfield> <mm:setfield name="to">daniel@mmbase.org</mm:setfield> <mm:setfield name="subject">my first mmbase email !!</mm:setfield> <mm:setfield name="body">Just testing email</mm:setfield> </mm:createnode> <!-- mail the email node --> <mm:node referid="mail1"> <mm:functioncontainer> <mm:param name="type" value="oneshot" /> <mm:function name="mail" /> </mm:functioncontainer> </mm:node> <!--check if mmbase could mail the message --> <mm:node referid="mail1"> <mm:field name="mailstatus"> <mm:compare value="1"> Mail was delivered at <mm:field name="mailedtime"><mm:time format=":LONG.LONG" /></mm:field> </mm:compare> <mm:compare value="2"> Mail failed </mm:compare> </mm:field> </mm:node>
Here you see 2 parts in the first we create the node and it is given an id so we can refer to it for sending and finding out what happened. The second part opens the email node and calls the mail function with the type oneshot (this time explicitely). Then in the third part we use the mail node again, just to show some status information about it.
<!-- create the email node --> <mm:createnode id="mail1" type="email"> <mm:setfield name="to">info@mmbase.org</mm:setfield> <mm:setfield name="from">daniel@mmbase.org</mm:setfield> <mm:setfield name="subject">MMBase group mail</mm:setfield> <mm:setfield name="body">Hi to all our group members !</mm:setfield> </mm:createnode> <!-- get the group node we want to mail --> <mm:node id="group1" number="groups.testgroep" /> <!-- create a relation to the group --> <mm:createrelation source="mail1" destination="group1" role="related" /> <!-- start the mailer and wait for it to finish --> <mm:node referid="mail1"> <mm:function name="mail" /> </mm:node>
If you are new to mmbase this seems a lot of lines but if you are already a user of the mmbase taglibs you will notice that the code is just based taglibs and if you are working with groups in your application you probably already have created it and you can add some lines. The example first creates a email object then gets the group that is defined by the mmbase alias "groups.testgroep" then a relation is created between the email object and the group. Lastly the mail(oneshot) command is given again. Since mmbase can't find a "to" field it will try to find if any users or groups with users are related to this email node and mails all the users it finds. The above example only finds a attached group with users but attached users work in the same way.
<mm:node referid="mail1"> <mm:functioncontainer> <mm:param name="type" value="oneshot" /> <mm:function name="startmail" /> </mm:functioncontainer> </mm:node>
<mm:node referid="mail1"> <mm:functioncontainer> <mm:param name="type" value="oneshotkeep" /> <mm:function name="startmail" /> </mm:functioncontainer> </mm:node>
(from example5.jsp) <!-- create the email node --> <mm:createnode id="mail1" type="email"> <mm:setfield name="from">daniel@submarine.nl</mm:setfield> <mm:setfield name="subject">http://localhost/mmexamples/jsp/email/example5_subject.jsp</mm:setfield> <mm:setfield name="body">http://localhost/mmexamples/jsp/email/example5_body.jsp</mm:setfield> </mm:createnode>
When the mail(..) or startmail(..) is called it will include the content found on the urls defined in subject and body. Also the email code will add a url param to the url. It will do this for each user it will mail. So say we have 2 users :
Daniel Ockeloen with user number : 320 Piet Hein with user number : 343 It will include for Daniel Ockeloen example5_subject.jsp?usernumber=320 for the subject example5_body.jsp?usernumer=320 for the body and for Piet Hein example5_subject.jsp?usernumber=343 for the subject example5_body.jsp?usernumer=343 for the body
The example5_subject.jsp : <%@taglib uri="http://www.mmbase.org/mmbase-taglib-2.0" prefix="mm" %> <mm:cloud> <mm:import externid="usernumber" /> <mm:node number="$usernumber">update for <mm:field name="firstname" /> <mm:field name="lastname" /> ! </mm:node> </mm:cloud>
As you can see there is nothing special in this page, it imports the usernumber param, opens the node and creates a subject line using the first and last name of the user. What is special is that MMBase will automatically remove all returns from the subject line since returns are not allowed in subject lines.
The example5_body.jsp <%@taglib uri="http://www.mmbase.org/mmbase-taglib-2.0" prefix="mm" %> <mm:cloud> <mm:import externid="usernumber" /> <mm:node number="$usernumber"> <p>Hi <mm:field name="firstname" /> <mm:field name="lastname" /> !</p> <p>Nice to see you again, These are your settings :</p> <p> firstname : <mm:field name="firstname" /><br/> lastname : <mm:field name="lastname" /><br/> email : <mm:field name="email" /><br/> account : <mm:field name="account" /><br/> password : <mm:field name="password" /><br/> </p> <p> Bye,<br /> MMBase Email Team.</p> </mm:node> </mm:cloud>
Same thing as with the subject a normal taglib page the body page is allowed to do any of the normal things to create the page you want. In this case ive assumed we want to mail people their account info. Now to allow for better control/layout of the email you can use the html >br /> and >p> tabs. If they are used in a body url we will convert them before emailing to single and dubble returns.
Todo : Tell about multipart mail (example6.jsp), mailing attachments (example7.jsp) <mm:setfield name="body"> <multipart id="plaintext" type="text/plain" encoding="UTF-8"> This is plain text ! </multipart> <multipart id="htmltext" alt="plaintext" type="text/html" encoding="UTF-8"> <h1>This is in html !</h1> </multipart> </mm:setfield>
The default configurations looks like this.
<properties> <property name="classes" type="map"> <entry><key>org.mmbase.module.smtp.Forwarder</key></entry> <entry><key>org.mmbase.module.smtp.VerifyEmailMailHandler</key></entry> <entry><key>org.mmbase.module.smtp.CloudMailHandler</key></entry> </property> </properties>
This also shows a few implementations, which will be a bit elaborated on in the next sections.
This is part of the MMBase documentation.
For questions and remarks about this documentation mail to: documentation@mmbase.org