Send unique code to user email I want to send a unique code to the user after registration. I know how to do custom modules. Also in the mail text send to the user I can see there are variables such as [user:name]. Should I define a variable and send it to the user?

Any help will be appreciated.

Thanks
I assume you will have to store that unique code somewhere because the user is going to use it and you will have to verify it against something?

I'd suggest to define a field for that unique code, you can use the field permissions module or a custom hook_field_access() to hide from the user. Then you generate that unique code in hook_user_presave() for new users and save in that field. The advantage of this is that you can then enable the token.module and you get tokens for all fields for free.

Alternatively, you can also store it in a custom table or $user->data and define hook_token_info() and hook_tokens() yourself. Instead of directly defining it as a token, you can also define it as a property (hook_entity_property_info()) to entity.module and it will automatically be available as a token as well if the entity_token module is enabled.

So yes, whichever way you chose, in the end it will be a token and you can use it in the mail.