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}",
"name(a)gmail.com".com", 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 <stephanie.roulland(a)gmail.com>om>:
> 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
> _______________________________________________
> users mailing list
> users(a)xwiki.org
>
http://lists.xwiki.org/mailman/listinfo/users