Hello,
(freely inspired/adapted by:
http://extensions.xwiki.org/xwiki/bin/view/Extension/Test+Mail (Vincent) and
http://xwiki.markmail.org/message/bksyjlpwezx4dgco?q=getAllMembersNamesForG…
(Sergiu)
Some questions:
to replace some text in velocity, I used $text.replaceAll(xxx,yyy).
Are they a way to use StringUtils tools in velocity?
http://commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/c…
If yes, how?
I failed to get email adress with
$userdoc.display("email","view",$user) function but without
"mailto:" prefix ...
http://maven.xwiki.org/site/docs/xwiki-javadoc-4.1.x/com/xpn/xwiki/api/Docu…
Are they a tip with wrappingSyntaxId value? or I must use regexp like i did?
If there are too much email I don't know if my macro is safe... (Perhaps there are a
way to insert a sleep instruction in velocity?)
Thxs
Anyway, here my script to send email at all xwiki users:
Note: to test/debug, modify this lines:
{{code}}
#if ($ToEmail != '' && $ToEmail == 'xxx.yyyy(a)nospam.fr')
##if ($ToEmail != '')
{{/code}}
----
{{velocity}}
#if($xwiki.hasAccessLevel('admin'))
#if ("$!{xwiki.getXWikiPreference('admin_email')}" != '')
#set ($RobotEmail="$!{xwiki.getXWikiPreference('admin_email')}")
#else
{{error}}You must fill admin email in Xwiki preference page{{/error}}
#end
## All Team Members on the Wiki (using velocity)
#set ($sql = ", BaseObject as obj where obj.name=doc.fullName and
obj.className='XWiki.XWikiUsers'")
#set ($allUsers = $xwiki.searchDocuments($sql))
#if("$!{request.action}" == 'send_mail' &&
"$!{request.lastname}" == '')
## Check submission and honey pot.
#if("$!request.subject" != '')
## loop on each email users
#foreach ($user in $allUsers)
#set ($userdoc = $xwiki.getDocument($user))
#set ($email = $userdoc.display("email","view",$user))
##Clean email adress (remove mailto:)
#set ($ToEmail = $email.replaceAll('^mailto:',''))
##SMTP adress to test/debug
##send to one user
#if ($ToEmail != '' && $ToEmail == 'xx.yy(a)nospam.fr')
##if ($ToEmail != '')
##send mail
##set($result = $xwiki.mailsender.sendTextMessage("no-reply(a)xwiki.com".com",
$request.recipient, $request.subject, "$!request.message"))
#set($result = $xwiki.mailsender.sendTextMessage("$RobotEmail",
"$ToEmail", $request.subject, "$!request.message"))
#if($result == -1)
{{error}}A problem occurred while sending the mail to $email.{{/error}}
#else
## {{info}}Everything went OK.{{/info}}
* mail sent to $email
#end
#end
#end
#else
{{error}}Please specify at least a subject{{/error}}
#end
#end
{{html wiki=true}}
<form action="" method="post">
<input name="action" value="send_mail" type="hidden"
/>
## this is a honey-pot hidden text field hat hopefully robots will not leave empty
<div class="hidden">
<input name="lastname" type="text" />
</div>
<fieldset>
**FROM** (admin email): $RobotEmail<br />
**SUBJECT:**<br />
<input type="text" name="subject" /><br />
**MESSAGE:**<br />
<textarea name="message" style="width:99%;" rows=10>Your test
message here.</textarea>
</fieldset>
<div>
<span class="buttonwrapper"><input type="submit"
class="button" value="Send" /></span>
</div>
</form>
{{/html}}
#else
{{error}}Oops. Area restricted to Admins, sorry.{{/error}}
#end
----
Liste des destinataires du mail ci-dessus (tous les membres de Iwiki):
= Recipient list: All Team Members on the Wiki (using velocity) =
#set ($sql = ", BaseObject as obj where obj.name=doc.fullName and
obj.className='XWiki.XWikiUsers'")
#set ($allUsers = $xwiki.searchDocuments($sql))
#foreach ($user in $allUsers)
#set ($userdoc = $xwiki.getDocument($user))
#set ($email = $userdoc.display("email","view",$user))
#set ($TexteMail = $email.replaceAll('^mailto:',''))
##set ($TexteMail =
$escapetool.xml($userdoc.display("email","view",$user)))
##set ($TexteMail =
StringUtils.removeStart("$userdoc.display("email","rendered",$user)",
"mailto"))
#if ($email != 'mailto:')
$user -> $email
##$user -> $email $TexteMail
#end
#end
{{/velocity}}
****************************
****************************
If you want to send email to a group, here the code to list email users by groups
(copy/paste the interesting piece):
{{velocity}}
Utilisateurs connectés actuellement:
$xwiki.rightsmanager.usersApi.allUsersNames
------
Liste tous mes groupes
#set($rightsAPI=$xwiki.rightsmanager)
#set($groupsAPI=$rightsAPI.getGroupsApi())
#set($groups=$groupsAPI.getAllLocalGroupsNames())
#foreach($group in $groups)
* [[$group]]
#end
-------
Get the email of all users in a group (using velocity)
## This request
##set ($sql = ", BaseObject as obj where obj.name=doc.fullName and
obj.className='XWiki.XWikiGroups'")
##set ($allGroups = $xwiki.searchDocuments($sql))
## OR thisAPI
#set($rightsAPI=$xwiki.rightsmanager)
#set($groupsAPI=$rightsAPI.getGroupsApi())
#set($allGroups=$groupsAPI.getAllLocalGroupsNames())
#foreach ($group in $allGroups)
* $group
#set ($groupdoc = $xwiki.getDocument($group))
##set ($groupMembers =
$util.sort($xwiki.rightsmanager.getAllMembersNamesForGroup($groupdoc.name)))
#set ($groupMembers =
$util.sort($xwiki.rightsmanager.getAllMembersNamesForGroup($group)))
## groupedoc.name $groupdoc.name
##set ($groupMembers =
$xwiki.rightsmanager.getAllMembersNamesForGroup("$groupdoc.name"))
#set ($groupMembers = $xwiki.rightsmanager.getAllMembersNamesForGroup($group))
##$groupMembers
#foreach ($mem in $groupMembers)
#set ($userdoc = $xwiki.getDocument($mem))
##set ($em = $userdoc.display("email","view",$mem)) $em<br>
#set ($em = $userdoc.display("email","view",$mem))
#if ($em != 'mailto:')
$em
#end
#end
#end
-------------
All Team Members on the Wiki (using velocity)
#set ($sql = ", BaseObject as obj where obj.name=doc.fullName and
obj.className='XWiki.XWikiUsers'")
#set ($allUsers = $xwiki.searchDocuments($sql))
#foreach ($user in $allUsers)
#set ($userdoc = $xwiki.getDocument($user))
#set ($mail = $userdoc.display("email","view",$user))
#if ($mail != 'mailto:')
$user $mail
#end
#end
{{/velocity}}
Pascal B
________________________________
De : Pascal BASTIEN <pbasnews-xwiki(a)yahoo.fr>
À : XWiki Users <users(a)xwiki.org>
Envoyé le : Mardi 26 août 2014 10h23
Objet : Re: [xwiki-users] Can I send email to a group with xwiki 6?
Sorry I didn't take the time to writing this loop (another priorities on Xwiki)
But I hope to find some time to writing it... :-)
________________________________
De : Shaddy <danigaglia89(a)gmail.com>
À : users(a)xwiki.org
Envoyé le : Mardi 26 août 2014 10h02
Objet : Re: [xwiki-users] Can I send email to a group with xwiki 6?
Pascal BASTIEN <pbasnews-xwiki@...> writes:
Thxs. I will use a loop then.
________________________________
Hello everybody,
I'm currently working on the same issue.
Can you show how you managed to send an email to a group of users??
Thank you very much.
Daniele.
_______________________________________________
users mailing list
users(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/users