> ## Documentation Index
> Fetch the complete documentation index at: https://stytch.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Send Email Magic Link

> Send email magic links using the Stytch Next.js SDK

The Send method wraps the [send](/api-reference/consumer/api/magic-links/via-email/send-magic-link) Email Magic Link API endpoint. This method requires that the user already exist within Stytch before a magic link may be sent. This method is useful for gating your login flow to only pre-created users, e.g. an invite or waitlist.

This method is also used when you need to add an email address to an existing Stytch User. If there is a currently valid Stytch session, and the user inputs an email address that does not match one on their Stytch User object, upon successful authentication the new email address will be appended to the emails array.

Note, this does expose a potential account enumeration vector, see our article on [preventing account enumeration](/resources/policies/platform/account-enumeration) for more details.

## Parameters

<ParamField body="email" type="string" required>
  The email address of the User to send the Magic Link to.
</ParamField>

<ParamField body="Configuration" type="object">
  Additional configuration.

  <Expandable title="properties">
    <ParamField body="login_magic_link_url" type="string">
      The URL the end user clicks from the login Email Magic Link. This should be a URL that your app receives and parses and subsequently send an API request to authenticate the Magic Link and log in the User. If this value is not passed, the default login redirect URL that you set in your Dashboard is used. If you have not set a default login redirect URL, an error is returned.
    </ParamField>

    <ParamField body="signup_magic_link_url" type="string">
      The URL the end user clicks from the sign-up Email Magic Link. This should be a URL that your app receives and parses and subsequently send an API request to authenticate the Magic Link and sign-up the User. If this value is not passed, the default sign-up redirect URL that you set in your Dashboard is used. If you have not set a default sign-up redirect URL, an error is returned.
    </ParamField>

    <ParamField body="login_expiration_minutes" type="int">
      Set the expiration for the login email magic link, in minutes. By default, it expires in 1 hour. The minimum expiration is 5 minutes and the maximum is 7 days (10080 mins).
    </ParamField>

    <ParamField body="signup_expiration_minutes" type="int">
      Set the expiration for the sign-up email magic link, in minutes. By default, it expires in 1 week. The minimum expiration is 5 minutes and the maximum is 7 days (10080 mins).
    </ParamField>

    <ParamField body="login_template_id" type="string">
      Use a custom template for login emails. By default, it will use your default email template. Templates can be added in the [Stytch dashboard](https://stytch.com/dashboard/templates) using our built-in customization options or custom HTML templates with type “Magic links - Login”.
    </ParamField>

    <ParamField body="signup_template_id" type="string">
      Use a custom template for sign-up emails. By default, it will use your default email template. Templates can be added in the [Stytch dashboard](https://stytch.com/dashboard/templates) using our built-in customization options or custom HTML templates with type “Magic links - Sign-up”.
    </ParamField>

    <ParamField body="locale" type="string">
      Used to determine which language to use when sending the user this delivery method. Parameter is an [IETF BCP 47 language tag](https://www.w3.org/International/articles/language-tags/), e.g. "en". Supported languages are English ("en"), Spanish ("es"), French ("fr") and Brazilian Portuguese ("pt-br"); if no value is provided, the copy defaults to English.
    </ParamField>
  </Expandable>
</ParamField>

## Response

<ResponseField name="request_id" type="string">
  Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we
  may ask for this value to help identify a specific API call when helping you debug an issue.
</ResponseField>

<ResponseField name="status_code" type="number">
  The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values
  equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
</ResponseField>

<Panel>
  <RequestExample>
    ```jsx theme={null}
    import { useStytch } from '@stytch/nextjs';

    export const Login = () => {
    const stytch = useStytch();

    const sendEmailMagicLink = () => {
      stytch.magicLinks.email.send('${email}', {
        login_magic_link_url: '${exampleURL}/authenticate',
        login_expiration_minutes: 5,
      });
    };

    return <button onClick={sendEmailMagicLink}>Send email</button>;
    };
    ```
  </RequestExample>

  <ResponseExample>
    ```json 200 theme={null}
    {
        "status_code": 200,
        "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141"
    }
    ```

    ```json 400 theme={null}
    {
      "status_code": 400,
      "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
      "error_type": "invalid_email",
      "error_message": "Email format is invalid.",
      "error_url": "https://stytch.com/docs/api/errors/400"
    }
    ```

    ```json 401 theme={null}
    {
      "status_code": 401,
      "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
      "error_type": "unauthorized_credentials",
      "error_message": "Unauthorized credentials.",
      "error_url": "https://stytch.com/docs/api/errors/401"
    }
    ```

    ```json 404 theme={null}
    {
      "status_code": 404,
      "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141"
      "error_type": "user_not_found",
      "error_message": "User could not be found.",
      "error_url": "https://stytch.com/docs/api/errors/404"
    }
    ```

    ```json 429 theme={null}
    {
      "status_code": 429,
      "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
      "error_type": "too_many_requests",
      "error_message": "Too many requests have been made.",
      "error_url": "https://stytch.com/docs/api/errors/429"
    }
    ```

    ```json 500 theme={null}
    {
      "status_code": 500,
      "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
      "error_type": "internal_server_error",
      "error_message": "Oops, something seems to have gone wrong, please reach out to support@stytch.com to let us know what went wrong.",
      "error_url": "https://stytch.com/docs/api/errors/500"
    }
    ```
  </ResponseExample>
</Panel>
