Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

How I can update the confluence users email addresses in bulk?




One of our use case, We need to update the all confluence users email addresses. I was trying to implement it through script, but somehow its not working. I was tried with UserAccessor & PersonalInformationManager services and its failing.

com.atlassian.user.User usr = (com.atlassian.user.User)userManager.getUser("suressak");
String email = "";
return "updated"
com.atlassian.user.User user = (com.atlassian.user.User)userAccessor.getUser("suressak");
PersonalInformation personalInfo = personalInformationManager.getOrCreatePersonalInformation(user);
return "updated"


Can you help on this? How I can achieve it?

Confluence Data center version : 6.6.11.

We are also using scriptrunner plugin. 

Thanks in advanced !!!


2 answers

1 accepted

0 votes
Answer accepted
import com.atlassian.sal.api.component.ComponentLocatorimport org.apache.log4j.Levelimport org.apache.log4j.Loggerimport com.atlassian.user.User     import com.atlassian.confluence.user.UserAccessorimport com.atlassian.confluence.user.ConfluenceUserimport com.atlassian.user.impl.DefaultUser  Logger  log = Logger.getLogger("")log.setLevel(Level.ALL)         try{"<------------------------------ User update activity started  -------------------------------------------->");File file = new File('/confluence-sb-uat/shared-home/scripts/azure_confluence_users.csv')def csvMapList = []  file.eachLine { line ->    def columns = line.split(",")    def tmpMap = [:]      tmpMap.putAt("original_username", columns[0])    tmpMap.putAt("new_username", columns[1])    tmpMap.putAt("original_email", columns[2])    tmpMap.putAt("new_email", columns[3])     csvMapList.add(tmpMap)}final String stringConstant = "New";csvMapList.each { map ->    try{                 String originalUserName = map.getAt("original_username")        String newUserName = map.getAt("new_username")        String originalEmail = map.getAt("original_email")        String newEmail = map.getAt("new_email"" : "+newUserName+" : "+originalEmail+" : "+newEmail);                UserAccessor userAccessor =  ComponentLocator.getComponent(UserAccessor)          if(userAccessor.exists(originalUserName)){            if(userAccessor.exists(newUserName)){                                   String renameNewUser = newUserName + stringConstant;                String renameEmail = newEmail + stringConstant;                /*Rename the new user's username & email*/                      ConfluenceUser usr = userAccessor.getUserByName(newUserName);                                  final DefaultUser mNewUser = new DefaultUser((User) usr);                    mNewUser.setEmail(renameEmail);                    userAccessor.saveUser((User)mNewUser);                                      userAccessor.renameUser(usr,renameNewUser);                                   /*disabled new user*/                userAccessor.deactivateUser((com.atlassian.user.User) userAccessor.getUserByName(renameNewUser));                                                   /*Update originalUser with New user's username & Email*/                try{                    ConfluenceUser originalUser = userAccessor.getUserByName(originalUserName);                    final DefaultUser mOriginalUser = new DefaultUser((User) originalUser);                    mOriginalUser.setEmail(newEmail);                    userAccessor.saveUser((User)mOriginalUser);                                          userAccessor.renameUser(originalUser,newUserName);          " :Old user updated successfully with new user's username:"+newUserName+" & email:"+newEmail);                }catch(e){                                        log.error("Something went wrong while updating the old user. Rollbacking new user rename operation. User:"+newUserName);                     ConfluenceUser usrRollback = userAccessor.getUserByName(renameNewUser);                                   userAccessor.reactivateUser((com.atlassian.user.User) usrRollback);                                           final DefaultUser mNewUserRollback = new DefaultUser((User) usrRollback);                     mNewUserRollback.setEmail(newEmail);                     userAccessor.saveUser((User)mNewUserRollback);                                       userAccessor.renameUser(usrRollback,newUserName);                                                                            }                                                                                    }else{                log.warn("New user not created yet. We are skiping the user update action for user:"+originalUserName);            }                       }else{            log.warn("user not found:"+originalUserName);        }             }catch(e){        log.warn("Something went wrong while updating the user : "+map.getAt("original_username")+" due to "+e.getMessage());     }       }"<------------------------------ User update activity end  -------------------------------------------->");}catch(e){    log.error("Something went wrong while updating the user "+e);}

I tried it successfully. This may help someone.  

Hi all, this script is now available in our script library for ScriptRunner for Confluence Server/DC (tested by our engineers).

Feel free to copy or customise it as you wish

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events