[xwiki-users] Send an email in an event listener
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}", "[email protected]", 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 -- View this message in context: http://xwiki.475771.n2.nabble.com/Send-an-email-in-an-event-listener-tp75791... Sent from the XWiki- Users mailing list archive at Nabble.com.
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}", "[email protected]", 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
Hello, Thank you for your answer, but I'm sorry, I don't understand what you mean by CM. Thanks, Stéphanie 2012/5/29 Vincent Massol <[email protected]>
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}", "[email protected]", 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 [email protected] http://lists.xwiki.org/mailman/listinfo/users
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 <[email protected]>
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}", "[email protected]", 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
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 ? In any case, thanks for your answer, Stéphanie 2012/5/29 vmassol [via XWiki] <[email protected]>
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>", 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 [hidden email] <http://user/SendEmail.jtp?type=node&node=7579201&i=2> http://lists.xwiki.org/mailman/listinfo/users
------------------------------ If you reply to this email, your message will be added to the discussion below:
http://xwiki.475771.n2.nabble.com/Send-an-email-in-an-event-listener-tp75791... To unsubscribe from Send an email in an event listener, click here<http://xwiki.475771.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=7579175&code=c3RlcGhhbmllLnJvdWxsYW5kQGdtYWlsLmNvbXw3NTc5MTc1fC0yNDI5MjU2Mjk=> . NAML<http://xwiki.475771.n2.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
-- 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 -- View this message in context: http://xwiki.475771.n2.nabble.com/Send-an-email-in-an-event-listener-tp75791... Sent from the XWiki- Users mailing list archive at Nabble.com.
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] <[email protected]>
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>", 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
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}", " [email protected]", 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 <[email protected]>
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] <[email protected]>
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>", 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 [email protected] 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
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() ? Thanks, Stéphanie 2012/5/29 Stéphanie Roulland <[email protected]>
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}", " [email protected]", 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 <[email protected]>
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] <[email protected]
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>", 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 [email protected] 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
On Tue, May 29, 2012 at 2:17 PM, Stéphanie Roulland <[email protected]> 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 <[email protected]>
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}", " [email protected]", 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 <[email protected]>
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] <[email protected]
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>", 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 [email protected] 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 [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne
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 <[email protected]>
On Tue, May 29, 2012 at 2:17 PM, Stéphanie Roulland <[email protected]> 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 <[email protected]>
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}", " [email protected]", 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 <[email protected]>
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] <
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>", 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 [email protected] 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 [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne _______________________________________________ users mailing list [email protected] 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
On Tue, May 29, 2012 at 4:31 PM, Stéphanie Roulland <[email protected]> wrote:
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 ...
source is actually a XWikiDocument and not a Document so it's not exactly the same methods. You need to add the XWikiContext object to the method call as second parameter (in case you don't already have it it's the data parameter coming with the event). You can look at https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwik... to get all the method.
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 <[email protected]>
On Tue, May 29, 2012 at 2:17 PM, Stéphanie Roulland <[email protected]> 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 <[email protected]>
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}", " [email protected]", 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 <[email protected]>
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] <
> > 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>", > 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 [email protected] 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 [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne _______________________________________________ users mailing list [email protected] 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 _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne
Hello,
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 ?
First, from your code :
def emailcontent = "Test" def result = xwiki.mailsender.sendHtmlMessage("${sender}", "[email protected]", emailcc, emailbcc, "Test du mail", emailcontent, document.getContent(), pageattachments)
... it's not evident to understand what you're trying to do. You provide your "emailcontent" as body content (so, HTML), and document.getContent() as alternate (plain text) variant, both don't seem to be alternates of the same content. By the way, I'm not sure of how your "document" variable is initialized at that point, maybe it would seem more logical to send "source.getContent()" ? Or just use the same content "Test" to be sure. In HTML part you would use "<br/>" to insert a line break, in plain text you would use "\n". Then it depends on what email client you use to check the received email content. Usually clients now manage HTML so you should receive the result of document.getContent(). If it's the plain text part that is displayed, then it depends on the client. Outlook might remove line-breaks that it doesn't like, so to be sure you could add a dot "." at the end of the line (!) and maybe double the line feed also : "\n\n". BR, Jeremie 2012/5/29 Stéphanie Roulland <[email protected]>:
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 <[email protected]>
On Tue, May 29, 2012 at 2:17 PM, Stéphanie Roulland <[email protected]> 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 <[email protected]>
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}", " [email protected]", 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 <[email protected]>
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] <
> > 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>", > 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 [email protected] 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 [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne _______________________________________________ users mailing list [email protected] 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 _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
participants (5)
-
Jeremie BOUSQUET -
Stéphanie -
Stéphanie Roulland -
Thomas Mortagne -
Vincent Massol