ManyMail Sandbox SMTP is an open-source project designed for developers to self-host a mail server for testing purposes. It offers features like concurrent SSL, TLS, and unauthenticated servers, a web interface for reading emails, and an API for programmatic email management.
- Key Features
- Quick Start
- Configuration
- API Endpoints
- Troubleshooting
- Usage Examples
- Valid alternatives
- Contributions
- Concurrent SMTP Servers: SSL, TLS, and no-authentication servers can run simultaneously.
- Web Interface: A simple UI for viewing received emails. Accessible at http://localhost:8080.
- API Access: REST API for managing and retrieving emails. Runs on port 8080.
- Authentication:
Unified username and password for SMTP servers and the web interface.
Credentials are stored in the
.env
file. - High Customizability:
Extensive configuration options via the
.env
file. Installation and Setup You can set up ManyMail Sandbox SMTP using npm or Docker.
-
Clone the repository and install npm packages:
git clone https://github.com/frarcos/manymail-sandbox.git cd manymail-sandbox npm install
-
(OPTIONAL) Configure the
.env
file (see details below). -
Start the server:
npm start
-
Send emails to the sandbox SMTP server (see examples below)
-
Access the web interface at http://localhost:8080 using the credentials specified in the
.env
file (ADMIN_USERNAME and ADMIN_PASSWORD).
- Clone the repository:
git clone https://github.com/frarcos/manymail-sandbox.git cd manymail-sandbox
- (OPTIONAL) Configure the
.env
file (see details below). - Build and run the Docker container.
For the docker execution, environment variables are stored in the environment section of the docker.compose.yml file, see env variables setup below
docker-compose -f docker-compose.yml up --build -d --force-recreate
- Send emails to the sandbox SMTP server (see examples below)
- Access the web interface at http://localhost:8080 using the credentials specified in the
.env
file (ADMIN_USERNAME and ADMIN_PASSWORD).
The .env
file is used to customize the behavior of ManyMail Sandbox SMTP. Below is a detailed explanation of each configuration:
Variable | Default | Description |
---|---|---|
ADMIN_USERNAME | root | Username for authentication in the web app and SMTP servers |
ADMIN_PASSWORD | root | Password for authentication in the web app and SMTP servers |
UNSECURE_SMTP_PORT | 25 | Port for the unauthenticated SMTP server |
SMTP_PORT | 465 | Port for the unauthenticated SMTP server |
STARTTLS_PORT | 587 | Port for the STARTTLS SMTP server |
RUN_UNSECURE_SMTP_SERVER | true | Set to true to enable the unauthenticated SMTP server (true/false) |
RUN_SMTP_SERVER | true | Set to true to enable the SSL SMTP server (true/false) |
RUN_STARTTLS_SERVER | true | Set to true to enable the STARTTLS SMTP server (true/false) |
ENABLE_LOGGING | true | Set to true to enable logging of server activities and API calls (true/false) |
MAX_STORED_MESSAGES | 1000000 | Maximum number of emails to store in memory |
SMTP_KEY_FILE | Path to the private key file for SSL/TLS. Required if SSL/TLS is enabled. | |
SMTP_CERT_FILE | Path to the certificate file for SSL/TLS. Required if SSL/TLS is enabled. |
The API runs on port 8080 and provides endpoints for managing emails programmatically. API docs are WIP.
- Cannot connect to SMTP servers:
Verify that the required ports (25, 465, 587) are not in use by another process.
Check the
.env
file for correct configurations. - Authentication issues:
Ensure ADMIN_USERNAME and ADMIN_PASSWORD are correctly set in the
.env
file. Restart the server after updating the .env. - SSL/TLS setup:
Ensure
SMTP_KEY_FILE
andSMTP_CERT_FILE
paths are valid and accessible.
import nodemailer from 'nodemailer';
const transporter = nodemailer.createTransport({
host: 'localhost',
port: 25,
secure: false,
tls: {
rejectUnauthorized: false,
},
});
const mailOptions = {
from: '"Sender Name" <your-email@example.com>',
to: 'recipient@example.com',
subject: 'Test Email',
text: 'Hello, this is a test email!',
html: `<b>Hello, this is a test email!</b>`,
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log('An error occurred:', error);
}
console.log('Email sent:', info.response);
});
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
host = "localhost"
port = 25
sender_email = "your-email@example.com"
recipient_email = "recipient@example.com"
subject = "Test Email"
text_body = "Hello, this is a test email!"
html_body = "<b>Hello, this is a test email!</b>"
message = MIMEMultipart("alternative")
message["From"] = f"Sender Name <{sender_email}>"
message["To"] = recipient_email
message["Subject"] = subject
message.attach(MIMEText(text_body, "plain"))
message.attach(MIMEText(html_body, "html"))
try:
with smtplib.SMTP(host, port) as server:
server.starttls() # Start TLS if needed
server.sendmail(sender_email, recipient_email, message.as_string())
print("Email sent successfully!")
except Exception as e:
print(f"An error occurred: {e}")
require 'mail'
# Mail setup
options = {
address: 'localhost',
port: 25,
enable_starttls_auto: false # Disable TLS verification
}
Mail.defaults do
delivery_method :smtp, options
end
# Create and send email
mail = Mail.new do
from 'Sender Name <your-email@example.com>'
to 'recipient@example.com'
subject 'Test Email'
text_part do
body 'Hello, this is a test email!'
end
html_part do
content_type 'text/html; charset=UTF-8'
body '<b>Hello, this is a test email!</b>'
end
end
begin
mail.deliver!
puts "Email sent successfully!"
rescue => e
puts "An error occurred: #{e}"
end
Here is a list of valid alternatives:
We welcome contributions! Feel free to fork the repository and submit a pull request.