How to Include custom tokens in the user register welcome mail Is it possible to use custom tokens in the default user regitration welcome mail? I need to pass variables from a custom module. Is the solution to create a token in the custom module and include it into the mail?
The user mail templates can be found at example.com/admin/config/people/accounts. The welcome mail for instance looks like this:


  [user:display-name],
  
  A site administrator at [site:name] has created an account for you.
  You may now log in by clicking this link or copying and pasting it
  into your browser:
  
  [user:one-time-login-url]
  
  This link can only be used once to log in and will lead you to a page
  where you can set your password.
  
  After setting your password, you will be able to log in at
  [site:login-url] in the future using:
  
  username: [user:name] password: Your password
  
  --  [site:name] team


As you can see there are already many tokens used. 

Furthermore, Drupal does not distinguish between core tokens and those of modules. So if a textfield allows you to use core tokens (like this one), you can also use any other token. If you create a custom token, you will be able to use it in the mail. BUT, you must keep in mind that this mail template only has access to a select set of tokens (click the Browse tokens link below the textarea):

Current date    current-date    Tokens related to the current date and time.
Current page    current-page    Tokens related to the current page request.
Current user    current-user    Tokens related to the currently logged in user.
Random  random  Tokens related to random data.
Site information    site    Tokens for site-wide settings and other global information.
Users   user    Tokens related to individual user accounts.


When working with tokens, each module can define which tokens it handles (The $data array passed to Token::replace()). In this specific case, it only gets the user entity of the created user. Apart from that, several global tokens are always available, these are Current date, Current page, Current user, Random and Site.

So your custom token must be provided within the user or site type.