How to send forget pass email programatically? I implemented Decoupled Drupal in one of my projects, one of the features I need to implement is a forget password feature. So I created a custom route to listen to reset password requested.

I know I can create a reset password URL with user_pass_reset_url(); I can generate this link and programmatically set the email to that user, but I am looking for a service or Drupal core functionality to achieve this job.

How can I programmatically send a reset password email?
With  some reverse engineering on core user module  the solution is :

    $name = \Drupal::request()-&gt;get("name");
    $langcode =  \Drupal::languageManager()-&gt;getCurrentLanguage()-&gt;getId();
    // Try to load by email.
    $users = \Drupal::entityTypeManager()-&gt;getStorage('user')-&gt;loadByProperties(array('mail' =&gt; $name));
    if (empty($users)) {
        // No success, try to load by name.
        $users = \Drupal::entityTypeManager()-&gt;getStorage('user')-&gt;loadByProperties(array('name' =&gt; $name));
    }
    $account = reset($users);
    // Mail one time login URL and instructions using current language.
    $mail = _user_mail_notify('password_reset', $account, $langcode);