Skip to content

PapercutSMTP

Not available until the next release main

Introduction

The Testcontainers module for Papercut SMTP, a lightweight SMTP server with a built-in web UI for capturing and inspecting outbound emails during testing. No messages are relayed to real recipients — all sent mail is held in memory and viewable through the web interface.

Adding this module to your project dependencies

Please run the following command to add the PapercutSMTP module to your Go dependencies:

go get github.com/testcontainers/testcontainers-go/modules/papercutsmtp

Usage example

ctx := context.Background()

papercutsmtpContainer, err := papercutsmtp.Run(ctx, "changemakerstudiosus/papercut-smtp:latest")
defer func() {
    if err := testcontainers.TerminateContainer(papercutsmtpContainer); err != nil {
        log.Printf("failed to terminate container: %s", err)
    }
}()
if err != nil {
    log.Printf("failed to start container: %s", err)
    return
}

Module Reference

Run function

  • Not available until the next release main

The PapercutSMTP module exposes one entrypoint function to create the PapercutSMTP container, and this function receives three parameters:

func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error)
  • context.Context, the Go context.
  • string, the Docker image to use.
  • testcontainers.ContainerCustomizer, a variadic argument for passing options.

Image

Use the second argument in the Run function to set a valid Docker image. In example: Run(context.Background(), "changemakerstudiosus/papercut-smtp:latest").

Container Options

When starting the PapercutSMTP container, you can pass options in a variadic way to configure it.

The following options are exposed by the testcontainers package.

Basic Options

Lifecycle Options

Files & Mounts Options

Build Options

Logging Options

Image Options

Networking Options

Advanced Options

Experimental Options

Container Methods

The PapercutSMTP container exposes the following methods:

SMTPEndpoint

  • Not available until the next release main

This method returns the host:port endpoint to connect to the SMTP server on port 2525.

smtpEndpoint, err := ctr.SMTPEndpoint(ctx)

HTTPURL

  • Not available until the next release main

This method returns the URL for the Papercut SMTP web UI on port 8080, where captured emails can be inspected.

httpURL, err := ctr.HTTPURL(ctx)