This was a very rapidly slung together form handler to take all the form fields from a WikiForm and email them to someone. Much work as originally posted has been updated, commented and the packaged into a jar file. A redirect parameter has been added so that, if the parameter is added, the user will be redirected to a new page on successful posting.
You need to set up the SMTP server to be used in the jspwiki.properties file like this...
jspwiki.formMailer.smtpHost = ''(your-host)''
and "org.jspwiki.plugins" to the plug-ins path as in:
jspwiki.plugin.searchPath = org.jspwiki.plugins
Install the jar file in <wiki home>/WEB-INF/lib
Parameters#
| mailerFrom | email address to send from |
| mailerTo | email address to send to |
| mailerCC | CC address |
| mailerBCC | Bcc address |
| mailerSubject | Subject line of the email |
| mailerRedirect | The wiki page to redirect to on success |
Example#
[{FormSet form='mailer' mailerFrom='wiki@somewhere.net' mailerTo='subscribe@somewhere.com' mailerSubject='Subscribe Me!' mailerRedirect='ThankYou'}]
[{FormOutput form='mailer' handler='FormMailerPlugin' populate='handler'}]
[{FormOpen form='mailer'}]
Title : [{FormSelect name='Title' value='Mr;Mrs;Ms;Miss;'}]\\
Name : [{FormInput type='text' name='FirstName'}]\\
Comments : [{FormTextarea name='Comments' rows=5 cols=40}]\\
[{FormInput type='submit' name='submit' value='Submit'}]
[{FormClose}]
This example will send an email from wiki@somwhere.net to subscribe@somwhere.net with the subject "Subscribe Me!" and the email body will be (for example)...
Title; Mr Name; Dave S-B Comments; Hi, just trying out this email lark...
The user will be redirected to the wiki page "ThankYou".
More help#
If you need more help with this then please feel free to use the contacts form at http://www.quru.com/contacts.html
ContributedFormHandlers
--Gerard Perreault, 2011-01-31
I liked the potential of this plugin but I found that it was lacking when it came to the actual email content. Obviously it was just meant as a test. So I tweaked a few things. For one thing, I did not use the "mailerFrom" parameter. Instead, I added a "mailerDomain" parameter which I use to create an email address by concatenating the user ID (not his name), the @ symbol and the mailerDomain value.
The new plugin will look for another page of the same name as the page containing the form fields, but with the word "Email" appended. For example, this FormMailerPlugin page would need a FormMailerPluginEmail page as template for the email to be sent. This provides some added security as a user creating a form can not email themselves a form they have no access to.
I did not investigate all the intricacies of allowing to send emails like this. You might want the code to be modified so that only authenticated users can send an email. And you might want to limit the number of email they can send at any given time to avoid your site being used to send spam. None of that is coded yet. :-)
Add new attachment
List of attachments
| Kind | Attachment Name | Size | Version | Date Modified | Author | Change note |
|---|---|---|---|---|---|---|
jar |
FormMailerPlugin.jar | 2.7 kB | 1 | 10-Jul-2009 00:06 | RolandW | Modified by Quru and correctly packaged |
java |
FormMailerPlugin.java | 5.7 kB | 2 | 10-Jul-2009 00:07 | RolandW | Modified by Quru with mailerRedirect added |
jar |
FormMailerPluginV2.jar | 7.1 kB | 1 | 01-Feb-2011 01:07 | Gerard Perreault | |
java |
FormMailerPluginV2.java | 6.1 kB | 1 | 01-Feb-2011 00:52 | Gerard Perreault |