How to add Mail account through code or API

I have implemented Keycloak(SSO) With Nextcloud. Now when I logged in to Nextcloud through KeyCloak(SSO), I am unable to view mail account in mail app. If I do login directly it works. But as per requirement, I have too use KeyCloak(SSO). I also can add Mail account with Manual Add. But it is not possible to add all accounts Manually, Because there are thousands of users who needs to access Nextcloud so can’t add manual account to each and everyone.
So,
Is there a way To add Mail Account through API? When I create user in keycloak and Nextcloud using APIs, I like to add mail account in Nextcloud through API. So When user login he/she can find out his working Mail App.
Or
I already make one user in Nextcloud same as Keycloak. So when I login with Keycloak, I want to get password of Nextcloud same user. I got password but unable to decrypt it. When I login directly I can clearly get password of that User in Base.php file but not with SSO login.

nextcloud/apps/mail/vendor/pear-pear.hodre.org/Horde_Imap_Client/Horde/Imap/Client/Base.php

We have account provisioning but that feature relies on the login password. If I understand correctly Nextcloud doesn’t know the password on your system as that part is fully handled by the SSO.

There are no APIs otherwise.

Ok. But when I login without SSO, I can mail app. Mail app requires user credentials. Here username/emailID and password. If I directly login Nextcloud have password and it sends to mail server with username/email and password. That is working fine. Password is encrypted in users table. That’s why I make same credentials for SSO(Keycloak) and Nextcloud. So I want to do is, when I login to Nextcloud using SSO, I can have email ID, I want to fetch password from database of that email ID. Because I am making same user in Nextcloud, I think I can get password too. But after getting password, it is in encrypted version. I don’t know how to decrypt that. If I login directly it gives me decrypted password that means there is a code where this encryption decryption is working but I am unable to find out that.

I’m sorry but I can’t follow.

Visit /settings/admin/groupware on your instance as admin. Those are the provisioning options Mail offers. Anything else we don’t support right now.