SMTP Users

Get a list of SMTP users

Retrieve information about account SMTP users with this GET request:

GET https://api.mailersend.com/v1/domains/{domain_id}/smtp-users

Request parameters

URL parameterTypeRequiredLimitationsDetails
domain_idstringyes
Query ParameterTypeRequiredLimitationsDetails
limitintnoMin: 10, Max: 100Default: 25
use MailerSend\MailerSend;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->smtpUser->getAll('domain-id', 25);

More examplesopen in new window

import 'dotenv/config';
import { MailerSend } from "mailersend";

const mailerSend = new MailerSend({
  apiKey: process.env.API_KEY,
});

mailerSend.email.smtpUser.list("domain-id")
    .then((response) => console.log(response.body))
    .catch((error) => console.log(error.body));

More examplesopen in new window

from mailersend import MailerSendClient, SmtpUsersBuilder

ms = MailerSendClient()

request = (SmtpUsersBuilder()
          .domain_id("domain-id")
          .build_smtp_users_list())

response = ms.smtp_users.list_smtp_users(request)

More examplesopen in new window

package main

import (
	"context"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

var APIKey = "Api Key Here"

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(APIKey)

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()

	domainID := "domain-id"
	options := &mailersend.ListSmtpUserOptions{
		Limit: 25,
	}

	_, _, err := ms.SmtpUser.List(ctx, domainID, options)
	if err != nil {
		log.Fatal(err)
	}
}

More examplesopen in new window

import com.mailersend.sdk.MailerSend;
import com.mailersend.sdk.smtpusers.SmtpUser;
import com.mailersend.sdk.smtpusers.SmtpUsersList;
import com.mailersend.sdk.exceptions.MailerSendException;

public void ListSmtpUsers() {
    
    MailerSend ms = new MailerSend();
    ms.setToken("api token");
    
    try {
        
        SmtpUsersList list = ms.smtpUsers().getSmtpUsers("domain-id", 25);
        
        for (SmtpUser smtpUser : list.smtpUsers) {
            
            System.out.println(smtpUser.id);
            System.out.println(smtpUser.name);
        }
        
    } catch (MailerSendException e) {
        
        e.printStackTrace();
    }
}

More examplesopen in new window

require "mailersend-ruby"

ms_smtp_user = Mailersend::SmtpUser.new
ms_smtp_user.list("domain-id")

More examplesopen in new window

Responses

Valid

Response Code: 200 OK
Response Headers:
	content-type: application/json
{
  "data": [
    {
      "id": "0wkg2zj19ovx5py7",
      "name": "Support SMTP",
      "username": "MS_bGQ0nV@mailerlite.com",
      "password": "W3XCfDM6NWs69puR",
      "enabled": true,
      "accessed_at": null,
      "server": "127.0.0.1",
      "port": 465,
      "domain_id": "7nxe3yjmeq28vp0k",
    }
  ]
}

Error

Response Code: 404 Not Found

Get a single SMTP user

If you want to retrieve a single account SMTP user, use this GET request:

GET https://api.mailersend.com/v1/domains/{domain_id}/smtp-users/{smtp_user_id}

Request parameters

URL parameterTypeRequiredLimitationsDetails
domain_idstringyes
smtp_user_idstringyes
use MailerSend\MailerSend;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->smtpUser->find('domain-id', 'smtp-user-id');

More examplesopen in new window

import 'dotenv/config';
import { MailerSend } from "mailersend";

const mailerSend = new MailerSend({
  apiKey: process.env.API_KEY,
});

mailerSend.email.smtpUser.single("domain-id", "smtp-user-id")
    .then((response) => console.log(response.body))
    .catch((error) => console.log(error.body));

More examplesopen in new window

from mailersend import MailerSendClient, SmtpUsersBuilder

ms = MailerSendClient()

request = (SmtpUsersBuilder()
          .domain_id("domain-id")
          .smtp_user_id("smtp-user-id")
          .build_smtp_user_get())

response = ms.smtp_users.get_smtp_user(request)

More examplesopen in new window

package main

import (
	"context"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

var APIKey = "Api Key Here"

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(APIKey)

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()

	domainID := "domain-id"
	smtpUserID := "smtp-user-id"

	_, _, err := ms.SmtpUser.Get(ctx, domainID, smtpUserID)
	if err != nil {
		log.Fatal(err)
	}
}

More examplesopen in new window

import com.mailersend.sdk.MailerSend;
import com.mailersend.sdk.smtpusers.SmtpUser;
import com.mailersend.sdk.exceptions.MailerSendException;

public void GetSmtpUser() {
    
    MailerSend ms = new MailerSend();
    ms.setToken("api token");
    
    try {
        
        SmtpUser smtpUser = ms.smtpUsers().getSmtpUser("domain-id", "smtp-user-id");
        
        System.out.println(smtpUser.id);
        System.out.println(smtpUser.name);
        System.out.println(smtpUser.username);
        
    } catch (MailerSendException e) {
        
        e.printStackTrace();
    }
}

More examplesopen in new window

require "mailersend-ruby"

ms_smtp_user = Mailersend::SmtpUser.new
ms_smtp_user.get("domain-id", "smtp-user-id")

More examplesopen in new window

Responses

Valid

Response Code: 200 OK
Response Headers:
	content-type: application/json
{
  "data": {
    "id": "0wkg2zj19ovx5py7",
    "name": "Support SMTP",
    "username": "MS_bGQ0nV@mailerlite.com",
    "password": "W3XCfDM6NWs69puR",
    "enabled": true,
    "accessed_at": null,
    "server": "127.0.0.1",
    "port": 465,
    "domain_id": "7nxe3yjmeq28vp0k"
  }
}

Error

Response Code: 404 Not Found

Add SMTP user

If you want to add a SMTP user to your domain, use this POST request:

POST https://api.mailersend.com/v1/domains/{domain_id}/smtp-users

Request parameters

URL parameterTypeRequiredLimitationsDetails
domain_idstringyes

Request Parameters

JSON parameters are provided in dot notation

JSON ParameterTypeRequiredLimitationsDetails
namestringyesMax 50 characters
enabledbooleanno
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\SmtpUserParams;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->smtpUser->create(
    'domain-id',
    (new SmtpUserParams('SMTP User Name'))
        ->setEnabled(true)
);

More examplesopen in new window

import 'dotenv/config';
import { MailerSend, SmtpUser } from "mailersend";

const mailerSend = new MailerSend({
  apiKey: process.env.API_KEY,
});

const smtpUser = new SmtpUser()
    .setName("SMTP User Name")
    .setEnabled(true);

mailerSend.email.smtpUser.create("domain-id", smtpUser)
    .then((response) => console.log(response.body))
    .catch((error) => console.log(error.body));

More examplesopen in new window

from mailersend import MailerSendClient, SmtpUsersBuilder

ms = MailerSendClient()

request = (SmtpUsersBuilder()
          .domain_id("domain-id")
          .name("SMTP User Name")
          .enabled(True)
          .build_smtp_user_create())

response = ms.smtp_users.create_smtp_user(request)

More examplesopen in new window

package main

import (
	"context"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

var APIKey = "Api Key Here"

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(APIKey)

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()

	domainID := "domain-id"
	options := &mailersend.CreateSmtpUserOptions{
		Name:    "SMTP User Name",
		Enabled: mailersend.Bool(true),
	}

	_, _, err := ms.SmtpUser.Create(ctx, domainID, options)
	if err != nil {
		log.Fatal(err)
	}
}

More examplesopen in new window

import com.mailersend.sdk.MailerSend;
import com.mailersend.sdk.smtpusers.SmtpUser;
import com.mailersend.sdk.exceptions.MailerSendException;

public void CreateSmtpUser() {
    
    MailerSend ms = new MailerSend();
    ms.setToken("api token");
    
    try {
        
        SmtpUser smtpUser = ms.smtpUsers().builder()
            .name("SMTP User Name")
            .enabled(true)
            .createSmtpUser("domain-id");
        
        System.out.println(smtpUser.id);
        System.out.println(smtpUser.name);
        
    } catch (MailerSendException e) {
        
        e.printStackTrace();
    }
}

More examplesopen in new window

require "mailersend-ruby"

ms_smtp_user = Mailersend::SmtpUser.new
ms_smtp_user.create("domain-id", name: "SMTP User Name", enabled: true)

More examplesopen in new window

Responses

Response KeyTypeDetails
dataobjectSMTP user object created.

Valid

Response Code: 201 CREATED
Response Headers:
	content-type: application/json
{
  "data": {
    "id": "480xl1qpeorzeg65",
    "name": "Support",
    "username": "MS_8PerdM@mailerlite.com",
    "password": "87GoZePLsPEKiGZR",
    "enabled": true,
    "accessed_at": null,
    "server": "127.0.0.1",
    "port": 465,
    "domain_id": "7nxe3yjmeq28vp0k"
  }
}

Invalid

Response Code: 422 Unprocessable Entity

See - Validation errors

Update SMTP user

If you want to update the information of an existing SMTP user, use this PUT request:

PUT https://api.mailersend.com/v1/domains/{domain_id}/smtp-users/{smtp_user_id}

Request Parameters

URL parameterTypeRequiredLimitationsDetails
domain_idstringyes
smtp_user_idstringyes

JSON parameters are provided in dot notation

JSON ParameterTypeRequiredLimitationsDetails
namestringyesMax 50 characters
enabledbooleanno
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\SmtpUserParams;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->smtpUser->update(
    'domain-id',
    'smtp-user-id',
    (new SmtpUserParams('Updated SMTP User Name'))
        ->setEnabled(false)
);

More examplesopen in new window

import 'dotenv/config';
import { MailerSend, SmtpUser } from "mailersend";

const mailerSend = new MailerSend({
  apiKey: process.env.API_KEY,
});

const smtpUser = new SmtpUser()
    .setName("Updated SMTP User Name")
    .setEnabled(false);

mailerSend.email.smtpUser.update("domain-id", "smtp-user-id", smtpUser)
    .then((response) => console.log(response.body))
    .catch((error) => console.log(error.body));

More examplesopen in new window

from mailersend import MailerSendClient, SmtpUsersBuilder

ms = MailerSendClient()

request = (SmtpUsersBuilder()
          .domain_id("domain-id")
          .smtp_user_id("smtp-user-id")
          .name("Updated SMTP User Name")
          .enabled(False)
          .build_smtp_user_update())

response = ms.smtp_users.update_smtp_user(request)

More examplesopen in new window

package main

import (
	"context"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

var APIKey = "Api Key Here"

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(APIKey)

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()

	domainID := "domain-id"
	smtpUserID := "smtp-user-id"
	options := &mailersend.UpdateSmtpUserOptions{
		Name:    mailersend.String("Updated SMTP User Name"),
		Enabled: mailersend.Bool(false),
	}

	_, _, err := ms.SmtpUser.Update(ctx, domainID, smtpUserID, options)
	if err != nil {
		log.Fatal(err)
	}
}

More examplesopen in new window

import com.mailersend.sdk.MailerSend;
import com.mailersend.sdk.smtpusers.SmtpUser;
import com.mailersend.sdk.exceptions.MailerSendException;

public void UpdateSmtpUser() {
    
    MailerSend ms = new MailerSend();
    ms.setToken("api token");
    
    try {
        
        SmtpUser smtpUser = ms.smtpUsers().builder()
            .name("Updated SMTP User Name")
            .enabled(false)
            .updateSmtpUser("domain-id", "smtp-user-id");
        
        System.out.println(smtpUser.id);
        System.out.println(smtpUser.name);
        
    } catch (MailerSendException e) {
        
        e.printStackTrace();
    }
}

More examplesopen in new window

require "mailersend-ruby"

ms_smtp_user = Mailersend::SmtpUser.new
ms_smtp_user.update("domain-id", "smtp-user-id", name: "Updated SMTP User Name", enabled: false)

More examplesopen in new window

Responses

Response KeyTypeDetails
dataobjectSMTP user object updated.

Valid

Response Code: 200 OK
Response Headers:
	content-type: application/json
{
  "data": {
    "id": "0z76k5jg0o3yeg2d",
    "name": "Support SMTP",
    "username": "MS_9sjABw@testing.com",
    "password": "ByeSJgB7Wc6tTm4a",
    "enabled": false,
    "accessed_at": null,
    "server": "127.0.0.1",
    "port": 465,
    "domain_id": "04mknvjymj87xp62"
  }
}

Invalid

Response Code: 422 Unprocessable Entity

See - Validation errors

Delete SMTP user

If you want to remove SMTP user, use this DELETE request:

DELETE https://api.mailersend.com/v1/domains/{domain_id}/smtp-users/{smtp_user_id}

Request parameters

URL parameterTypeRequiredLimitationsDetails
domain_idstringyes
smtp_user_idstringyes
use MailerSend\MailerSend;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->smtpUser->delete('domain-id', 'smtp-user-id');

More examplesopen in new window

import 'dotenv/config';
import { MailerSend } from "mailersend";

const mailerSend = new MailerSend({
  apiKey: process.env.API_KEY,
});

mailerSend.email.smtpUser.delete("domain-id", "smtp-user-id")
    .then((response) => console.log(response.body))
    .catch((error) => console.log(error.body));

More examplesopen in new window

from mailersend import MailerSendClient, SmtpUsersBuilder

ms = MailerSendClient()

request = (SmtpUsersBuilder()
          .domain_id("domain-id")
          .smtp_user_id("smtp-user-id")
          .build_smtp_user_delete())

response = ms.smtp_users.delete_smtp_user(request)

More examplesopen in new window

package main

import (
	"context"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

var APIKey = "Api Key Here"

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(APIKey)

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()

	domainID := "domain-id"
	smtpUserID := "smtp-user-id"

	_, _, err := ms.SmtpUser.Delete(ctx, domainID, smtpUserID)
	if err != nil {
		log.Fatal(err)
	}
}

More examplesopen in new window

import com.mailersend.sdk.MailerSend;
import com.mailersend.sdk.exceptions.MailerSendException;

public void DeleteSmtpUser() {
    
    MailerSend ms = new MailerSend();
    ms.setToken("api token");
    
    try {
        
        ms.smtpUsers().deleteSmtpUser("domain-id", "smtp-user-id");
        
        System.out.println("SMTP user deleted successfully");
        
    } catch (MailerSendException e) {
        
        e.printStackTrace();
    }
}

More examplesopen in new window

require "mailersend-ruby"

ms_smtp_user = Mailersend::SmtpUser.new
ms_smtp_user.delete("domain-id", "smtp-user-id")

More examplesopen in new window

Responses

Valid

Response Code: 204 OK

Error

Response Code: 404 Not Found
Last Updated: