# Change email address for sending

**URL:** <https://forum.keycloak.org/t/change-email-address-for-sending/27156>\
**Category:** Extending the server\
**Created:** [July 25, 2024, 9:26am UTC](https://forum.keycloak.org/t/change-email-address-for-sending/27156 "2024-07-25T09:26:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![deanmaster](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/deanmaster/32/10935_2.png) [@deanmaster](https://forum.keycloak.org/u/deanmaster)\
**Post date:** [July 25, 2024, 9:26am UTC](https://forum.keycloak.org/t/change-email-address-for-sending/27156/1 "2024-07-25T09:26:31Z")

</div>

Hello everyone,

I know the default behavior of sending email in Keycloak will always trigger with `email` attribute from User which makes sence. On the other hand, i have business case where the `email` field is used for different purposes and we would like to send email to another field value like `custom attribute for email sending`

I read the code of `org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider#send(java.lang.String, java.util.List<java.lang.Object>, java.lang.String, java.util.Map<java.lang.String,java.lang.Object>)` and the method does not allow to pass in address.

I looked at protected method `org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider#send(java.util.Map<java.lang.String,java.lang.String>, java.lang.String, java.lang.String, java.lang.String, java.lang.String)` and I can see you can pass in address as the last attribute.

I have options either i have to clone UserModel and set email attribute directly because setting email attribute to the same userModel will trigger update email attribute of User which we don’t want.

Inherit org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider which I do not know how to register the implement in Keycloak.

Thanks a lot for any hints,  
Tuan Do

---

<div class="post-metadata">

**Author:** ![dasniko](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/dasniko/32/2969_2.png) [@dasniko](https://forum.keycloak.org/u/dasniko)\
**Post date:** [July 25, 2024, 10:23am UTC](https://forum.keycloak.org/t/change-email-address-for-sending/27156/2 "2024-07-25T10:23:46Z")

</div>

You can just extend the default `FreeMarkerEmailTemplateProvider` and corresponding `...Factory` classes and return a higher `order` value in the factory class. This way, the Keycloak will use your implementation.

Or you implement your custom provider/factory and configure it as the default to be used, like described here: [Configuring providers - Keycloak](https://www.keycloak.org/server/configuration-provider#_configuring_a_default_provider_for_an_spi)

BTW: mentioning methods with only the types of the arguments, not the names, makes it very hard to read and finding the proper method you are referring to. Also, repeated usage of full package names bloats the text. Consider to mention it e.g. like `send(Map<String, String> config, String subject, String textBody, String htmlBody, String address)` which is easier to read and understand.

---

<div class="post-metadata">

**Author:** ![deanmaster](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/deanmaster/32/10935_2.png) [@deanmaster](https://forum.keycloak.org/u/deanmaster)\
**Post date:** [July 25, 2024, 10:47am UTC](https://forum.keycloak.org/t/change-email-address-for-sending/27156/3 "2024-07-25T10:47:17Z")

</div>

Perfect exactly thanks, that’s what i’m implementing right now. By enable this new email provide during starting of Keycloak. Thanks a lot for quick support
