Confirmation email Content

I am running Version 16.2.0
The email template for the "Confirmation email Content " is

#set ($wikiname = $request.serverName)
#set ($host = ${request.getRequestURL()})
#set ($host = ${host.substring(0, ${host.indexOf('/', ${mathtool.add(${host.indexOf('//')}, 2)})})})
Content-Type: text/plain; charset=utf-8
Subject: Dein Account auf ${wikiname} wurde aktiviert

Hallo ${xwiki.getUserName("$xwikiname", false)},

Dein Account auf ${wikiname} wurde erfolgreich aktiviert. Du kannst dich nun unter ${host}${xwiki.getURL('XWiki.XWikiLogin', 'login')} mit deinem Benutzernamen (${xwiki.getDocument($xwikiname).documentReference.name}) anmelden.

The parameter (${xwiki.getDocument($xwikiname).documentReference.name}) is not filled with the username but is printed as is.
What is the correct expression for the username?

To debug you can try putting the code ${xwiki.getDocument($xwikiname).documentReference.name} inside a {{velocity}}...{{/velocity}} macro in a wiki page (with the value xwikiname set ofc).

You can also modify your template to print the various parts in it, to find out what is nott working. For example:

* $xwiki
* $xwikiname
* $xwiki.getDocument($xwikiname)
* $xwiki.getDocument($xwikiname).documentReference
* $xwiki.getDocument($xwikiname).documentReference.name

$xwiki is working
$xwikiname is not working

what do you mean with ‘(with the value xwikiname set ofc)’

Is this something that was modified in your instance or is the default in XWiki?

I’ve never used this feature. @ilie.andriuta is that something you’ve tested?

Thx

So I’ve checked and the default template for English is:

#set ($wikiname = $request.serverName)
#set ($host = ${request.getRequestURL()})
#set ($host = ${host.substring(0, ${host.indexOf('/', ${mathtool.add(${host.indexOf('//')}, 2)})})})
Content-Type: text/plain; charset=utf-8
Subject: Your account on ${wikiname} has been activated

Hello ${xwiki.getUserName("$xwikiname", false)},

Your account on ${wikiname} has been successfully activated. You can now login at ${host}${xwiki.getURL('XWiki.XWikiLogin', 'login')} using your username (${xwiki.getDocument($xwikiname).documentReference.name}).

Which is the same as yours. @ilie.andriuta is testing in German.

This formula is not calculated

Actually there doesn’t seem to be a German version. I’m assuming you’ve done the translation yourself in the Admin UI.

EDIT: However, Ilie has tested and the mail received is ok

is this when you modify the template? Could you show how you achieved this?

xwikiname is correctly injected in the code at xwiki-platform/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/XWiki.java at 3a8c2fe395f766d40426b9b5f2559680484c591d · xwiki/xwiki-platform · GitHub

I tried this inside a {{velocity}}...{{/velocity}} macro in a wiki page
Yes, I did the translation in the AdminUI.

ah but that’s normal it’s not working!! You most likely haven’t defined the value of $xwikiname :slight_smile:

My point was for you try this inside the template content.

Now I tried it in the mail template, ErniBerni123 is the username

$xwiki
$xwikiname
$xwiki.getDocument($xwikiname)
$xwiki.getDocument($xwikiname).documentReference
$xwiki.getDocument($xwikiname).documentReference.name

will be filled in the mail with

com.xpn.xwiki.api.XWiki@42f75f85
XWiki.ErniBerni123
$xwiki.getDocument($xwikiname)
$xwiki.getDocument($xwikiname).documentReference
$xwiki.getDocument($xwikiname).documentReference.name

ok so this is the part that is not working. It’s weird though as I don’t see what’s wrong with $xwiki.getDocument("XWiki.ErniBerni123").

Maybe try this in a standalone wiki page using the {{velocity}} macro to see what you get and check the xwiki logs too. Could the XWiki.ErniBerni123 page have some special permissions set on it?

my only guess is that the user used to send the mail doesn’t have view rights on that page, as the code checks for this at xwiki-platform/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/api/XWiki.java at 14b5462c47ff7b776de3544bcb4dedfaf6fb30c8 · xwiki/xwiki-platform · GitHub

What will be the full URL of the XWiki.ErniBerni123 page?
I found the users profile page at
https://mywikisaddress/xwiki/bin/view/XWiki/ErniBerni123
there is no page
https://mywikisaddress/xwiki/bin/view/XWiki.ErniBerni123

yes that’s the one. What is specified is the reference.

I can open the reference with my user and admin rights. Looks like a normal user page.
I just checked the logs when registering a new user. I couldn’t find anything unnormal.

The error definitely has something to do with the rights of the new user. Apparently the mail template is executed with the rights of the new user. However, the new user does not have the right (in our xWiki) to call this function / reference.

I solved it now by using

Your account on ${wikiname} has been successfully activated. You can now login at ${host}${xwiki.getURL('XWiki.XWikiLogin', 'login')} using your username ($xwikiname.split("[.]")[1]).

instead of the function

(${xwiki.getDocument($xwikiname).documentReference.name})

for the username

were you able to test this?

Yes, I tested this in a standalone wiki page using the {{velocity}} macro, but I had to define the parameter xwikiname. On the wiki page the parameter xwikiname was undefined

#set ($wikiname = $request.serverName)
wikiname = $wikiname
#set ($host = ${request.getRequestURL()})
host = $host
#set ($host = ${host.substring(0, ${host.indexOf('/', ${mathtool.add(${host.indexOf('//')}, 2)})})})
host_kurz = $host
#set ($xwikiname_test = 'XWiki.ErniBerni123')
xwikiname_test = $xwikiname_test
#set ($usern = $xwikiname_test.split("[.]")[1])
usern = $usern