Skip to content

IMAP SMTP inbox access

MailSlurp mailboxes provide IMAP and SMTP access to your email accounts. This allows you to control inboxes using your favourite email client or using SMTP/IMAP libraries in any language you choose.

Access endpoints

Protocol Host Port TLS Description
SMTP mx.mailslurp.com 2525 false SMTP server
IMAP mailslurp.click 1143 false IMAP server
HTTP(S) api.mailslurp.com 80 true REST API server

Creating an SMTP inbox

To access an inbox with SMTP or IMAP you must create a new inbox using the SMTP_INBOX mailbox type. Once created you will see a username and password for each protocol in the dashboard. You can also obtain access credentials using the API.

import {CreateInboxDtoInboxTypeEnum, MailSlurp} from 'mailslurp-client';
const apiKey = process.env.API_KEY;
const mailslurp = new MailSlurp({ apiKey });

// create an smtp inbox
const inboxSmtp = await mailslurp.inboxController.createInboxWithOptions({
    createInboxDto: {
        inboxType: CreateInboxDtoInboxTypeEnum.SMTP_INBOX,
    }
});

Get access credentials

Each mailbox has a unique username and password for connection with the SMTP and IMAP servers. Use the getImapSmtpAccessDetails method to list access credentials:

// get access details
const {
    smtpServerHost,
    smtpServerPort,
    smtpUsername,
    smtpPassword,
    imapUsername,
    imapPassword,
    imapServerHost,
    imapServerPort,
} = await mailslurp.getImapSmtpAccessDetails(inboxSmtp.id)

Connect using SMTP client in code

To control a mailbox in code using an SMTP library use the credentials, host and port to configure your library. Here is an example in NodeJS using the popular nodemailer package.

import nodemailer from "nodemailer";

const transport = nodemailer.createTransport({
    host: server.smtpServerHost,
    port: server.smtpServerPort,
    secure: false,
    auth: {
        user: server.smtpUsername,
        pass: server.smtpPassword,
        type: "PLAIN"
    }
})

Sending emails with SMTP

SMTP is for sending emails. You must use IMAP or the MailSlurp API methods to read emails.

Sending email to a MailSlurp inbox using SMTP

You can send emails to a MailSlurp inbox without any credentials like so:

const transport = nodemailer.createTransport({
    host: "mx.mailslurp.com",
    port: 2525,
    secure: false
})

const sent = await transport.sendMail({
    from: '"Fred Foo 👻" <foo@example.com>',
    to: inbox.emailAddress,
    subject: "Hello ✔",
    text: "Hello world?",
    html: "<b>Hello world?</b>",
});

Send emails from an inbox

To send emails from a MailSlurp inbox you must use the credentails associated with it to verify your ownership. Pass the SMTP auth details using PLAIN method.

const opts = {
    host: server.smtpServerHost,
    port: server.smtpServerPort,
    secure: false,
    auth: {
        user: server.smtpUsername,
        pass: server.smtpPassword,
        type: "PLAIN"
    },
}
// Create auth plain transport
const transport = nodemailer.createTransport(opts)

// Send email
const sent = await transport.sendMail({
    from: inbox.emailAddress,
    to: inbox.emailAddress,
    subject: "Test outbound email",
    text: "Can I send on behalf?",
    html: "<b>Hello world</b>",
});