---
layout: article
title: SMTP
description: Send emails to your Appwrite users using SMTP and Appwrite Messaging.
back: /docs/
---
If you wish to use a third-party SMTP provider that Appwrite doesn't yet support or host your own SMTP
server, you can setup a custom SMTP provider for your project.

## 1. Add provider

To add a custom SMTP server as a provider, navigate to **Messaging** > **Providers** > **Add provider** > **Email**.

![Add a SMTP provider](/images/docs/messaging/providers/smtp/add-smtp.avif)

Give your provider a name > choose **SMTP** > click **Save and continue**.
The provider will be saved to your project, but not enabled until you complete its configuration.

## 2. Configure provider

In the **Configure** step, you will need to provide details from your SMTP dashboard to connect your Appwrite project.

You will need to provide the following information from your **SMTP dashboard**.

| Field name | Description |
| --- | --- |
| Host | The server address of the SMTP provider. |
| Port | The port used for SMTP connections. |
| Username | Your SMTP provider account username. |
| Password | Your SMTP provider account password. |
| Encryption | The type of encryption used. One of SSL or TLS. |
| Auto TLS | Automatically uses TLS encryption if available. |
| Mailer | The SMTP server or provider. |
| Sender email | The provider sends emails from this sender email. The sender email needs to be an email under the configured domain. |
| Sender name | The sender name that appears in the emails sent from this provider. |
| Reply-to email | The reply-to email that appears in the emails sent from this provider. The reply-to email needs to be an email under the configured domain. |
| Reply-to name | The reply-to name that appears in the emails sent from this provider. |

After adding the following details, click **Save and continue** to enable the provider.

## 3. Test provider

Before sending your first message,
make sure you've configured [a topic](/docs/products/messaging/topics) and [a target](/docs/products/messaging/targets) to send messages to.

**Console**

To send a test message, navigate to **Messaging** > **Messages** > **Create message** > **Email**.

![Create email message](/images/docs/messaging/messages/create-email-message.avif)

Add your message and in the targets step, select one of your test targets. Set the schedule to **Now** and click **Send**.

Verify that you can receive the message in your inbox. If not, check for logs in the Appwrite Console or in your provider's logs.

**Server SDK**

To send a message programmatically, use an [Appwrite Server SDK](/docs/sdks#server).

```server-nodejs
const sdk = require('node-appwrite');

// Init SDK
const client = new sdk.Client();

const messaging = new sdk.Messaging(client);

client
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<PROJECT_ID>') // Your project ID
    .setKey('<API_KEY>') // Your secret API key
;

const message = await messaging.createEmail({
  messageId: '<MESSAGE_ID>',
  subject: '<SUBJECT>',
  content: '<CONTENT>'
});
```
```deno
import * as sdk from "npm:node-appwrite";

// Init SDK
let client = new sdk.Client();

let messaging = new sdk.Messaging(client);

client
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<PROJECT_ID>') // Your project ID
    .setKey('<API_KEY>') // Your secret API key
;

const message = await messaging.createEmail({
  messageId: '<MESSAGE_ID>',
  subject: '<SUBJECT>',
  content: '<CONTENT>'
});
```
```php
<?php

use Appwrite\Client;
use Appwrite\Services\Messaging;

$client = new Client();

$client
    ->setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    ->setProject('<PROJECT_ID>') // Your project ID
    ->setKey('<API_KEY>') // Your secret API key
;

$messaging = new Messaging($client);

$result = $messaging->createEmail('<MESSAGE_ID>', '<SUBJECT>', '<CONTENT>');
```
```python
from appwrite.client import Client

client = Client()

(client
  .set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
  .set_project('<PROJECT_ID>') # Your project ID
  .set_key('<API_KEY>') # Your secret API key
)

messaging = Messaging(client)

result = messaging.create_email(
    message_id='<MESSAGE_ID>',
    subject='<SUBJECT>',
    content='<CONTENT>'
)
```
```ruby
require 'appwrite'

include Appwrite

client = Client.new
    .set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
    .set_project('<PROJECT_ID>') # Your project ID
    .set_key('<API_KEY>') # Your secret API key

messaging = Messaging.new(client)

response = messaging.create_email(message_id: '<MESSAGE_ID>', subject: '<SUBJECT>', content: '<CONTENT>')

puts response.inspect
```
```csharp
using Appwrite;
using Appwrite.Services;
using Appwrite.Models;
using Appwrite.Enums;
using Appwrite.Enums;
using Appwrite.Enums;

var client = new Client()
    .SetEndPoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
    .SetProject("<PROJECT_ID>") // Your project ID
    .SetKey("<API_KEY>"); // Your secret API key

var messaging = new Messaging(client);

Message result = await messaging.CreateEmail(
    messageId: "<MESSAGE_ID>",
    subject: "<SUBJECT>",
    content: "<CONTENT>");
```
```dart
import 'package:dart_appwrite/dart_appwrite.dart';
import 'package:dart_appwrite/enums.dart';
import 'package:dart_appwrite/models.dart';

void main() async { // Init SDK
  Client client = Client();
  Messaging messaging = Messaging(client);

  client
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<PROJECT_ID>') // Your project ID
    .setKey('<API_KEY>') // Your secret API key
  ;

  Future result = await messaging.createEmail(
    messageId:'<MESSAGE_ID>' ,
    subject:'<SUBJECT>' ,
    content:'<CONTENT>' ,
  );

  result
    .then((response) {
      print(response);
    }).catchError((error) {
      print(error.response);
  });
}
```
```kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Messaging

val client = Client()
    .setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<PROJECT_ID>") // Your project ID
    .setKey("<API_KEY>") // Your secret API key

val messaging = Messaging(client)

val response = messaging.createEmail(
    messageId = "<MESSAGE_ID>",
    subject = "<SUBJECT>",
    content = "<CONTENT>",
)
```
```java
import io.appwrite.Client;
import io.appwrite.coroutines.CoroutineCallback;
import io.appwrite.services.Messaging;

Client client = new Client()
    .setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<PROJECT_ID>") // Your project ID
    .setKey("<API_KEY>"); // Your secret API key

Messaging messaging = new Messaging(client);

messaging.createEmail(
    "<MESSAGE_ID>",
    "<SUBJECT>",
    "<CONTENT>",
    new CoroutineCallback<>((result, error) -> {
        if (error != null) {
            error.printStackTrace();
            return;
        }

        System.out.println(result);
    })
);
```
```swift
import Appwrite

let client = Client()
    .setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<PROJECT_ID>") // Your project ID
    .setKey("<API_KEY>") // Your secret API key

let messaging = Messaging(client)

let message = try await messaging.createEmail(
    messageId: "<MESSAGE_ID>",
    subject: "<SUBJECT>",
    content: "<CONTENT>"
)
```
```server-rust
use appwrite::Client;
use appwrite::services::messaging::Messaging;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new()
        .set_endpoint("https://<REGION>.cloud.appwrite.io/v1")
        .set_project("<PROJECT_ID>")
        .set_key("<API_KEY>");

    let messaging = Messaging::new(&client);

    let message = messaging.create_email(
        "<MESSAGE_ID>",                              // messageId
        "<SUBJECT>",                                 // subject
        "<CONTENT>",                                 // content
        None,                                        // topics (optional)
        None,                                        // users (optional)
        None,                                        // targets (optional)
        None,                                        // cc (optional)
        None,                                        // bcc (optional)
        None,                                        // attachments (optional)
        None,                                        // draft (optional)
        None,                                        // html (optional)
        None,                                        // scheduledAt (optional)
    ).await?;

    println!("{:?}", message);
    Ok(())
}
```

You can follow the [Send email messages](/docs/products/messaging/send-push-notifications) guide to send your first push notification and test your provider.

## 4. Manage provider

**Console**

You can update or delete a provider in the Appwrite Console.

Navigate to **Messaging** > **Providers** > click your provider.
In the settings, you can update a provider's configuration or delete the provider.

**Server SDK**

To update or delete providers programmatically, use an [Appwrite Server SDK](/docs/sdks#server).

```server-nodejs
const sdk = require('node-appwrite');

// Init SDK
const client = new sdk.Client();

const messaging = new sdk.Messaging(client);

client
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<PROJECT_ID>') // Your project ID
    .setKey('<API_KEY>') // Your secret API key
;

// update provider
messaging.updateSmtpProvider({
    providerId: '<PROVIDER_ID>',
    name: '<PROVIDER_NAME>',
    host: '<HOST>',
    port: 587,
    username: '<USERNAME>',
    password: '<PASSWORD>',
    encryption: sdk.SmtpEncryption.Tls,
    autoTLS: true,
    mailer: '<MAILER>',
    fromName: '<SENDER_NAME>',
    fromEmail: '<SENDER_EMAIL>',
    replyToName: '<REPLY_TO_NAME>',
    replyToEmail: '<REPLY_TO_EMAIL>',
    enabled: true
}).then(function (response) {
    console.log(response);
}, function (error) {
    console.log(error);
});

// delete provider
messaging.deleteProvider({
    providerId: '<PROVIDER_ID>'
})
.then(function (response) {
    console.log(response);
}, function (error) {
    console.log(error);
});
```
```deno
import * as sdk from "npm:node-appwrite";

// Init SDK
let client = new sdk.Client();

let messaging = new sdk.Messaging(client);

// update provider
messaging.updateSmtpProvider({
    providerId: '<PROVIDER_ID>',
    name: '<PROVIDER_NAME>',
    host: '<HOST>',
    port: 587,
    username: '<USERNAME>',
    password: '<PASSWORD>',
    encryption: sdk.SmtpEncryption.Tls,
    autoTLS: true,
    mailer: '<MAILER>',
    fromName: '<SENDER_NAME>',
    fromEmail: '<SENDER_EMAIL>',
    replyToName: '<REPLY_TO_NAME>',
    replyToEmail: '<REPLY_TO_EMAIL>',
    enabled: true
}).then(function (response) {
    console.log(response);
}, function (error) {
    console.log(error);
});

// delete provider
messaging.deleteProvider({
    providerId: '<PROVIDER_ID>'
})
.then(function (response) {
    console.log(response);
}, function (error) {
    console.log(error);
});
```
```php
<?php

use Appwrite\Client;
use Appwrite\Services\Messaging;

$client = new Client();

$client
    ->setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    ->setProject('<PROJECT_ID>') // Your project ID
    ->setKey('<API_KEY>') // Your secret API key
;

$messaging = new Messaging($client);

$result = $messaging->updateSendgridProvider(
    '<PROVIDER_ID>',
    '<PROVIDER_NAME>',
    '<API_KEY>',
    '<DOMAIN>',
    '<IS_EU_REGION?>',
    '<SENDER_NAME>',
    '<SENDER_EMAIL>',
    '<REPLY_TO_NAME>',
    '<REPLY_TO_EMAIL>',
    '<ENABLED?>',
);
```
```python
from appwrite.client import Client

client = Client()

(client
  .set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
  .set_project('<PROJECT_ID>') # Your project ID
  .set_key('<API_KEY>') # Your secret API key
)

messaging = Messaging(client)

result = messaging.update_smtp_provider(
    provider_id='<PROVIDER_ID>',
    name='<PROVIDER_NAME>',
    host='<HOST>',
    port=587,
    username='<USERNAME>',
    password='<PASSWORD>',
    encryption='tls',
    auto_tls=True,
    mailer='<MAILER>',
    from_name='<SENDER_NAME>',
    from_email='<SENDER_EMAIL>',
    reply_to_name='<REPLY_TO_NAME>',
    reply_to_email='<REPLY_TO_EMAIL>',
    enabled=True,
)
```
```ruby
require 'appwrite'

include Appwrite

client = Client.new
    .set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
    .set_project('<PROJECT_ID>') # Your project ID
    .set_key('<API_KEY>') # Your secret API key

messaging = Messaging.new(client)

response = messaging.update_sendgrid_provider(
    provider_id: "<PROVIDER_ID>",
    name: "<PROVIDER_NAME>",
    api_key: "<API_KEY>",
    domain: "<DOMAIN>",
    isEuRegion: "<IS_EU_REGION?>",
    from_name: "<SENDER_NAME>",
    from_email: "<SENDER_EMAIL>",
    reply_to_name: "<REPLY_TO_NAME>",
    reply_to_email: "<REPLY_TO_EMAIL>",
    enabled: "<ENABLED?>",
)

puts response.inspect
```
```csharp
using Appwrite;
using Appwrite.Services;
using Appwrite.Models;
using Appwrite.Enums;

var client = new Client()
    .SetEndPoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
    .SetProject("<PROJECT_ID>") // Your project ID
    .SetKey("<API_KEY>"); // Your secret API key

var messaging = new Messaging(client);

Provider result = await messaging.UpdateSendgridProvider(
    providerId: "<PROVIDER_ID>",
    name: "<PROVIDER_NAME>",
    apiKey: "<API_KEY>",
    domain: "<DOMAIN>",
    isEuRegion: "<IS_EU_REGION?>",
    fromName: "<SENDER_NAME>",
    fromEmail: "<SENDER_EMAIL>",
    replyToName: "<REPLY_TO_NAME>",
    replyToEmail: "<REPLY_TO_EMAIL>",
    enabled: "<ENABLED?>",
);
```
```dart
import 'package:dart_appwrite/dart_appwrite.dart';
import 'package:dart_appwrite/enums.dart';
import 'package:dart_appwrite/models.dart';

void main() { // Init SDK
  Client client = Client();
  Messaging messaging = Messaging(client);

  client
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<PROJECT_ID>') // Your project ID
    .setKey('<API_KEY>') // Your secret API key
  ;

  Future result = messaging.updateSendgridProvider(
    providerId: "<PROVIDER_ID>",
    name: "<PROVIDER_NAME>",
    apiKey: "<API_KEY>",
    domain: "<DOMAIN>",
    isEuRegion: "<IS_EU_REGION?>",
    fromName: "<SENDER_NAME>",
    fromEmail: "<SENDER_EMAIL>",
    replyToName: "<REPLY_TO_NAME>",
    replyToEmail: "<REPLY_TO_EMAIL>",
    enabled: "<ENABLED?>",
  );

  result
    .then((response) {
      print(response);
    }).catchError((error) {
      print(error.response);
  });
}
```
```kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Messaging

val client = Client()
    .setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<PROJECT_ID>") // Your project ID
    .setKey("<API_KEY>") // Your secret API key

val messaging = Messaging(client)

val response = messaging.updateSendgridProvider(
    providerId = "<PROVIDER_ID>",
    name = "<PROVIDER_NAME>",
    apiKey = "<API_KEY>",
    domain = "<DOMAIN>",
    isEuRegion = "<IS_EU_REGION?>",
    fromName = "<SENDER_NAME>",
    fromEmail = "<SENDER_EMAIL>",
    replyToName = "<REPLY_TO_NAME>",
    replyToEmail = "<REPLY_TO_EMAIL>",
    enabled = "<ENABLED?>",
)

```
```java
import io.appwrite.Client;
import io.appwrite.coroutines.CoroutineCallback;
import io.appwrite.services.Messaging;

Client client = new Client()
    .setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<PROJECT_ID>") // Your project ID
    .setKey("<API_KEY>"); // Your secret API key

Messaging messaging = new Messaging(client);

messaging.updateSendgridProvider(
    "<PROVIDER_ID>",
    "<PROVIDER_NAME>",
    "<API_KEY>",
    "<DOMAIN>",
    "<IS_EU_REGION?>",
    "<SENDER_NAME>",
    "<SENDER_EMAIL>",
    "<REPLY_TO_NAME>",
    "<REPLY_TO_EMAIL>",
    "<ENABLED?>",
    new CoroutineCallback<>((result, error) -> {
        if (error != null) {
            error.printStackTrace();
            return;
        }

        System.out.println(result);
    })
);
```
```swift
import Appwrite

let client = Client()
    .setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<PROJECT_ID>") // Your project ID
    .setKey("<API_KEY>") // Your secret API key

let messaging = Messaging(client)

let provider = try await messaging.updateSendgridProvider(
    providerId: "<PROVIDER_ID>",
    name: "<PROVIDER_NAME>",
    apiKey: "<API_KEY>",
    domain: "<DOMAIN>",
    isEuRegion: "<IS_EU_REGION?>",
    fromName: "<SENDER_NAME>",
    fromEmail: "<SENDER_EMAIL>",
    replyToName: "<REPLY_TO_NAME>",
    replyToEmail: "<REPLY_TO_EMAIL>",
    enabled: "<ENABLED?>",
)
```
```server-rust
use appwrite::Client;
use appwrite::services::messaging::Messaging;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new()
        .set_endpoint("https://<REGION>.cloud.appwrite.io/v1")
        .set_project("<PROJECT_ID>")
        .set_key("<API_KEY>");

    let messaging = Messaging::new(&client);

    // update provider
    let provider = messaging.update_smtp_provider(
        "<PROVIDER_ID>",                             // providerId
        Some("<PROVIDER_NAME>"),                     // name (optional)
        Some("<HOST>"),                              // host (optional)
        Some(587),                                   // port (optional)
        Some("<USERNAME>"),                          // username (optional)
        Some("<PASSWORD>"),                          // password (optional)
        None,                                        // encryption (optional)
        Some(true),                                  // autoTLS (optional)
        Some("<MAILER>"),                            // mailer (optional)
        Some("<SENDER_NAME>"),                       // fromName (optional)
        Some("<SENDER_EMAIL>"),                      // fromEmail (optional)
        Some("<REPLY_TO_NAME>"),                     // replyToName (optional)
        Some("<REPLY_TO_EMAIL>"),                    // replyToEmail (optional)
        Some(true),                                  // enabled (optional)
    ).await?;

    // delete provider
    messaging.delete_provider("<PROVIDER_ID>").await?;

    println!("{:?}", provider);
    Ok(())
}
```
