> 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/integrate-the-email-sdk.md).

# Integrate the Email SDK

## Prerequisites <a href="#prerequisites" id="prerequisites"></a>

1. [​Complete the Getting Started Guide​](/guides/getting-started.md)
2. ​[Integrate the User SDK​](/guides/users/integrate-the-user-sdk.md)
3. [​Integrate the Sudo Profiles SDK​](/guides/sudos/integrate-the-sudo-sdk.md)

## Get Started <a href="#get-started" id="get-started"></a>

* [Integrate the JS SDK](#integrate-the-js-sdk)
* [​Integrate the iOS SDK​](#integrate-the-ios-sdk)
* [​Integrate the Android SDK​](#integrate-the-android-sdk)

## Integrate the JS SDK

To use the **Email SDK** in a Web or Node.js project, you must add `@sudoplatform/sudo-email` as a dependency to your project.

```javascript
yarn add '@sudoplatform/sudo-email'
# or
npm install --save '@sudoplatform/sudo-email'
```

{% hint style="info" %}
In order to instantiate an Email client, make sure you have followed instructions for [Getting Started](/guides/getting-started.md), [User SDK](/guides/users/integrate-the-user-sdk.md) and [Sudo Profiles SDK](/guides/sudos/integrate-the-sudo-sdk.md) (see [Prerequisites](#prerequisites) above).
{% endhint %}

To instantiate and initialize a client in your application, add the following:

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

```javascript
import { DefaultApiClientManager } from '@sudoplatform/sudo-api-client'
import { DefaultConfigurationManager } from '@sudoplatform/sudo-common'
import { DefaultSudoEmailClient } from '@sudoplatform/sudo-email'
import { DefaultSudoProfilesClient } from '@sudoplatform/sudo-profiles'
import { DefaultSudoUserClient } from '@sudoplatform/sudo-user'

const sdkConfigJSON = /* ... refer to Users documentation ... */
DefaultConfigurationManager.getInstance().setConfig(sdkConfigJSON)

const userClient = new DefaultSudoUserClient(/* refer to Users documentation */)
const profilesClient = new DefaultSudoProfilesClient(/* refer to Sudos documentation */)
const apiClientManager = DefaultApiClientManager.getInstance().setAuthClient(userClient)

const emailClient = new SudoEmailClient(
    apiClientManager
    userClient,
    profilesClient,
)
```

{% endtab %}
{% endtabs %}

## Integrate the iOS SDK <a href="#integrate-the-ios-sdk" id="integrate-the-ios-sdk"></a>

To use the Email SDK in an iOS app, you need to install the SudoEmail package via Swift Package Manager

Open your project settings in XCode, and go to the `Package Dependencies` tab. Click on the `+` sign to add a dependency.&#x20;

Enter the repository URL [`https://github.com/sudoplatform/sudo-email-ios`](https://github.com/sudoplatform/sudo-email-ios) in the top right search box and select the `sudo-email-ios` repository.&#x20;

Select the required version and `Add Package`.&#x20;

Sudo Platform SDKs conform to semantic versioning so in most cases you will leave the Dependency Rule as `Up to Next Major Version` to receive regular updates without introducing any breaking changes.

This will resolve the local package dependency and install the latest version of the Email SDK.

{% hint style="info" %}
In order to instantiate an Email client, make sure you have followed instructions for [Getting Started](/guides/getting-started.md), [User SDK](/guides/users/integrate-the-user-sdk.md) and [Sudo Profiles SDK](/guides/sudos/integrate-the-sudo-sdk.md) (see [Prerequisites](#prerequisites) above)
{% endhint %}

To instantiate a client in your application, add the following:

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

```swift
import SudoEmail
import SudoUser

let userClient = // ... see "Users" docs

let emailClient = try DefaultSudoEmailClient(
    keyNameSpace: "MyNameSpace",
    sudoUserClient: userClient
)
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
You only need one client instance for a given user per device. Instantiating multiple clients with the same configuration and using them at the same time may cause unexpected runtime errors to occur.
{% endhint %}

{% hint style="success" %}
**See it in action.** Be sure to take a look at the [open source iOS sample app](https://github.com/sudoplatform/samples-ios) on GitHub that our team published as a reference for integrating the **Email SDK** into your app as quickly and seamlessly as possible.
{% endhint %}

## Integrate the Android SDK <a href="#integrate-the-android-sdk" id="integrate-the-android-sdk"></a>

The Android SDK is open source and compatible with Android 7 (API level 24) and above.

{% tabs %}
{% tab title="Gradle" %}
Add this line to the dependencies section of the app module `build.gradle` and synchronize your project with Android Studio.

```groovy
dependencies {
    implementation 'com.sudoplatform:sudoemail:$latest_version'
}
```

{% hint style="info" %}
The latest version of the SDK can be found at [SDK Releases](/guides/email/sdk-releases.md).
{% endhint %}

{% hint style="info" %}
In order to instantiate an Email client, make sure you have followed instructions for [Getting Started](/guides/getting-started.md) and [User SDK](/guides/users/integrate-the-user-sdk.md) and [Sudo Profiles SDK ](/guides/sudos/integrate-the-sudo-sdk.md)(see Prerequisities above)
{% endhint %}
{% endtab %}
{% endtabs %}

To instantiate a client in your application, add the following:

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

```kotlin
val userClient = // ... see "Users" docs

val emailClient = SudoEmailClient.builder()
    .setContext(appContext) 
    .setSudoUserClient(userClient)
    .build()
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
You only need one client instance for a given user per device. Instantiating multiple clients with the same configuration and using them at the same time may cause unexpected runtime errors to occur.
{% endhint %}

{% hint style="success" %}
**See it in action.** Be sure to take a look at the [open source Android sample app](https://github.com/sudoplatform/samples-android) on Github that our team published as a reference for integrating the **Email SDK** into your app as quickly and seamlessly as possible.
{% endhint %}

### Authentication

In order to successfully invoke any methods on the Email Client, the User Client must be authenticated (signed in). See [Authentication](/guides/users/authentication.md) for more details on how to implement the sign in process.

Authentication can be done explicitly as part of application bootstrap, or you may provide a callback which implements the signIn process. If such a callback is provided, it will be invoked whenever an email SDK method is called and the userClient is not already signed in. &#x20;

Set the sign in callback to empty to remove this behaviour.

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

```typescript
// Define the callback, it will likely invoke userClient.signIn or
// similar depending on your required processing
  const callback: SudoPlatformSignInCallback = {
    signIn: async () => {
      // Perform signIn processing here.
    },
  }

// Call setSignInCallback
emailClient.setSignInCallback(callback)
```

{% endtab %}

{% tab title="Swift" %}

```swift
// Define the delegate, it will likely invoke userClient.signIn or
// similar depending on your required processing
class EmailSignInDelegate: SudoPlatformSignInDelegate {
    func signIn() async throws {
         // Perform signIn processing here.
    }
}

// Call setSignInDelegate
let delegate = EmailAddressSignInDelegate()
await emailClient.setSignInDelegate(delegate)
```

{% endtab %}

{% tab title="Kotlin" %}

```kt
// Define the callback, it will likely invoke userClient.signIn or
// similar depending on your required processing
class EmailSignInCallback : SudoPlatformSignInCallback {
   override suspend fun signIn() {
      // Perform signIn processing here.
   }
}

// Call setSignInCallback
val callback = new EmailSignInCallback()
emailClient.setSignInCallback(callback)
```

{% endtab %}
{% endtabs %}
