> For the complete documentation index, see [llms.txt](https://docs.sudoplatform.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sudoplatform.com/guides/email/email-masks/verifying-external-email-addresses.md).

# Verifying External Email Addresses

If you provide the option to provision Email Masks that are associated with an external (i.e. Non-Sudo Platform Email Service) email address, the Mask will initially have its `state` set to `PENDING`. While in this state, the Mask will not be able to receive (or reply to) messages. In order to change its `state` to `ENABLED` , you must verify that the user owns the email address. To do this, you must call the `verifyExternalEmailAddress` method. This will trigger a One-Time Passcode (OTP) verification flow in which an email will be sent to the email address with a six-digit code that must then be passed into another call to `verifyExternalEmailAddress`  for verification.

{% hint style="info" %}
Note that this process is **not** needed for Email Masks associated with a Sudo Platform email address.
{% endhint %}

### Sending the One-Time Passcode

To initiate the OTP flow, first call `verifyExternalEmailAddress` with the `id` of the Email Mask being enabled and the email address to verify.

{% tabs %}
{% tab title="TypeScript" %}

```typescript
const emailMaskId: string = emailMask.id // Get the Email Mask from the `provisionEmailMask` method
const emailAddress: string // The email address must match the one passed in as the `realAddress` property of `provisionEmailMask`
try {
    await emailClient.verifyExternalEmailAddress({
        emailMaskId: emailMaskId,
        emailAddress: emailAddress,
    })
    // At this point, the method should return `undefined`
} catch (e) {
    // Handle/notify user of errors
}
```

{% endtab %}

{% tab title="Swift" %}

```
// To be added
```

{% endtab %}

{% tab title="Kotlin" %}

```
// To be added
```

{% endtab %}
{% endtabs %}

After this call, the user should receive an email from the Sudo Platform Email Service with the OTP that will need to be passed into the next call.

{% hint style="info" %}
In order to use this functionality, you must define a domain for the email to come from, as well as provide an HTML template for the email body. Your solutions engineer can assist you in setting this up.
{% endhint %}

### Verifying the One-Time Passcode

Once the user has received the OTP from their email address, it must be passed in to another call to `verifyExternalEmailAddress` to be verified by the service. If that is successful, the Email Mask will have its `state` updated to `ENABLED` and it will be ready to use.

{% tabs %}
{% tab title="TypeScript" %}

```typescript
const emailMaskId: string = emailMask.id // Get the Email Mask from the `provisionEmailMask` method
const emailAddress: string // The email address must match the one passed in as the `realAddress` property of `provisionEmailMask`
const verificationCode: string // The code that the user has retrieved from the email sent to their real email address
try {
    const result = await emailClient.verifyExternalEmailAddress({
        emailMaskId: emailMaskId,
        emailAddress: emailAddress,
        verificationCode: verificationCode
    })
    // `result.isVerified` will be true if verification was successful, and the Email Mask will have its state set to ENABLED
    // If it was not, then `result.reason` will contain a string with the reason it failed
} catch (e) {
    // Handle/notify user of errors
}
```

{% endtab %}

{% tab title="Swift" %}

```
// To be added
```

{% endtab %}

{% tab title="Kotlin" %}

```
// To be added
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.sudoplatform.com/guides/email/email-masks/verifying-external-email-addresses.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
