Thank you all for your answers. I have two last questions and everything
will be perfect after that :D
When defining my variable "emailcontent" (the body of my email), I want to
write a little text with a link to the page (= the source of the event).
Question 1 : Is it possible to have the URL of the document and how ? I've
tried ${source.getExternalURL('view')}, but as source is an Object and not
a Document, it doens't work at all ...
Question 2 : How can I make a line break on the text of my mail ? I've
tried <br/>, \n, %0D%0A, but nothing work ... Do you have a solution ?
Again, thank you everyone for your answers.
Stéphanie
2012/5/29 Thomas Mortagne <thomas.mortagne(a)xwiki.com>
  On Tue, May 29, 2012 at 2:17 PM, Stéphanie Roulland
 <stephanie.roulland(a)gmail.com> wrote:
  I don't know how I do that, but it works :D
 I have an other question : what is the difference between these two 
 events
  : DocumentUpdateEvent() and DocumentSaveEvent() ?
 That's actually old deprecated events (and indeed the naming was not very
 good).
 The new events are:
 org.xwiki.observation.event.DocumentUpdateEvent ->
 org.xwiki.bridge.event.DocumentUpdatedEvent
 org.xwiki.observation.event.DocumentSaveEvent ->
 org.xwiki.bridge.event.DocumentCreatedEvent
 I'm sure the new names are a bit more clear ;)
 Thanks,
 Stéphanie
 2012/5/29 Stéphanie Roulland <stephanie.roulland(a)gmail.com>
> I've only one page called "EventListener" with this code :
>
> {{groovy}}
> import org.xwiki.observation.*
> import org.xwiki.observation.event.*
> import com.xpn.xwiki.web.*
> import com.xpn.xwiki.*
> class LoggingEventListener implements EventListener{
>     def xwiki
>     def context
>     LoggingEventListener(xwiki, context)
>     {
>         this.xwiki = xwiki
>         this.context = context
>     }
>     String getName()
>     {
>         // The unique name of this event listener
>         return "logging"
>     }
>     List<Event> getEvents()
>     {
>         // The list of events this listener listens to
>         return Arrays.asList(new DocumentSaveEvent())
>     }
>     // Called by the Observation Manager when an event matches the list 
 of
 > events returned
>     // by getEvents()
>
>     void onEvent(Event event, Object source, Object data)
>     {
>         // Prevent infinite recursion since in this example we log to 
 wiki
 > page which
>         // triggers a document change... :)
>         if (source.fullName != "Main.Logger") {
>    def sender = context.user.substring(6)
>    def emailcc = xwiki.null
>    def emailbcc = xwiki.null
>    def pageattachments = []
>    def emailcontent = "ceci est un test du mail"
>    def result = xwiki.mailsender.sendHtmlMessage("${sender}", "
> stephanie.roulland(a)dcnsgroup.com"quot;, emailcc, emailbcc, "Test du mail",
> emailcontent, document.getContent(), pageattachments)
>
>             def document = xwiki.getDocument("Main.Logger")
>             document.setContent("ça marche Sender : ${sender} / Content 
 :
 > ${emailcontent}")
>
>             document.save("Logging event", true)
>         }
>     }}
> // Register against the Observation Manager
> def observation = Utils.getComponent(ObservationManager.class)
> observation.removeListener("logging")
> def listener = new LoggingEventListener(xwiki, xcontext)
> observation.addListener(listener)
> {{/groovy}}
>
> Have I forgotten something ?
>
> Thanks,
> Stéphanie
>  2012/5/29 Vincent Massol <vincent(a)massol.net>
>
>>
>> On May 29, 2012, at 1:22 PM, Stéphanie wrote:
>>
>> > I'm really sorry, I don't understand all this kind of specific words
 ^^
 >> Do
>> > you want the entire code ? Or what do you want exactly ?
>>
>> Sorry I meant Observation Manager, not Component Manager.
>> See
>> 
http://platform.xwiki.org/xwiki/bin/view/DevGuide/GroovyNotificationTutorial
 >>
>> Thanks
>> -Vincent
>>
>> > In any case, thanks for your answer,
>> > Stéphanie
>> >
>> > 2012/5/29 vmassol [via XWiki] < 
ml-node+s475771n7579201h35(a)n2.nabble.com
 >> >
>> >
>> >>
>> >> On May 29, 2012, at 1:07 PM, Stéphanie Roulland wrote:
>> >>
>> >>> Hello,
>> >>>
>> >>> Thank you for your answer, but I'm sorry, I don't understand
what 
 you
 >> >> mean
>> >>> by CM.
>> >>
>> >> Component Manager.
>> >>
>> >> -Vincent
>> >>
>> >>> Thanks,
>> >>> Stéphanie
>> >>>
>> >>> 2012/5/29 Vincent Massol <[hidden email]<
>> 
http://user/SendEmail.jtp?type=node&node=7579201&i=0>>
>>  >>
>> >>>
>> >>>> FYI I've just done this in a training I gave last week and
it 
 worked
 >> >>>> nicely.
>> >>>>
>> >>>> Can you show us the code you've used to register the event
 listener
 >> >>>> against the CM?
>> >>>>
>> >>>> Thanks
>> >>>> -Vincent
>> >>>>
>> >>>> On May 29, 2012, at 9:12 AM, Stéphanie wrote:
>> >>>>
>> >>>>> Hello everyone,
>> >>>>>
>> >>>>> I'm trying to send an automatic email and this is the
idea I have
>> had.
>> >>>>>
>> >>>>> I used the "Groovy Notification Tutorial"
>> >>>>> (
>> >>>>
>> >>
>> 
http://platform.xwiki.org/xwiki/bin/view/DevGuide/GroovyNotificationTutorial
 >> >>>> )
>> >>>>> and instead of writing in a file, I try to send an email.
>> >>>>>
>> >>>>> This is my code (I only copy the method onEvent, I
didn't change 
 the
 >> >>>> rest) :
>> >>>>>
>> >>>>>  void onEvent(Event event, Object source, Object data)
>> >>>>>  {
>> >>>>>      // Prevent infinite recursion since in this example we
log 
 to
    >> wiki
 >>>>> page which
 >>>>>      // triggers a document change... :)
 >>>>>      if (source.fullName != "Main.Logger") {
 >>>>>                     def sender = context.user.substring(6)
 >>>>>                     def emailcc = xwiki.null
 >>>>>                     def emailbcc = xwiki.null
 >>>>>                     def pageattachments = []
 >>>>>                     def emailcontent = "Test"
 >>>>>                     def result =
 >>>> xwiki.mailsender.sendHtmlMessage("${sender}",
 >>>>> "[hidden email] <
 
http://user/SendEmail.jtp?type=node&node=7579201&i=1>"mp;i=1>",
 >> emailcc, emailbcc, "Test du mail", emailcontent,
 >>>>> document.getContent(), pageattachments)
 >>>>>          def document = xwiki.getDocument("Main.Logger")
 >>>>>          document.setContent("Sender : ${sender} / Content :
 >>>>> ${emailcontent}")
 >>>>>          document.save("Logging event", true)
 >>>>>      }
 >>>>>  }
 >>>>>
 >>>>> But when I try this, nothing happened. I don't have any error
 message
 >> so
 >>>> I
 >>>>> don't know if I make something wrong.
 >>>>>
 >>>>> Do you have an idea of how doing this ?
 >>>>>
 >>>>> Thank you very much for your future answer,
 >>>>> Stéphanie
 _______________________________________________
 users mailing list
 users(a)xwiki.org
 
http://lists.xwiki.org/mailman/listinfo/users
 
  --
 Stéphanie ROULLAND
 06.74.85.37.90
 -------------------------
 Contrat de professionnalisation DCNS
 Ingénieur domaine collaboratif
 02.29.05.42.23
 -------------------------
 Elève ingénieur ENIB
 3ème année cycle ingénieur
 Option informatique
 
 
 --
 Stéphanie ROULLAND
 06.74.85.37.90
 -------------------------
 Contrat de professionnalisation DCNS
 Ingénieur domaine collaboratif
 02.29.05.42.23
 -------------------------
 Elève ingénieur ENIB
 3ème année cycle ingénieur
 Option informatique
 _______________________________________________
 users mailing list
 users(a)xwiki.org
 
http://lists.xwiki.org/mailman/listinfo/users  
 --
 Thomas Mortagne
  _______________________________________________
 users mailing list
 users(a)xwiki.org
 
http://lists.xwiki.org/mailman/listinfo/users
 
--
Stéphanie ROULLAND
06.74.85.37.90
-------------------------
Contrat de professionnalisation DCNS
Ingénieur domaine collaboratif
02.29.05.42.23
-------------------------
Elève ingénieur ENIB
3ème année cycle ingénieur
Option informatique