Skip to content

Commit 613c5d7

Browse files
committed
Initial commit
0 parents  commit 613c5d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3214
-0
lines changed

.dockerignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Binary
2+
mail-sink
3+
4+
# Dependency directories
5+
ui/node_modules/
6+
7+
# Build outputs
8+
ui/dist/
9+
10+
# Log files
11+
*.log
12+
13+
# Mac OS
14+
.DS_Store
15+
16+
# Editor files
17+
.vscode/
18+
.idea/
19+
*.swp
20+
*.swo
21+
22+
# Go specific
23+
*.exe
24+
*.exe~
25+
*.dll
26+
*.so
27+
*.dylib
28+
*.test
29+
*.out
30+
go.work
31+
32+
# NPM/Yarn
33+
package-lock.json
34+
yarn.lock
35+
36+
# Logs
37+
logs
38+
*.log
39+
npm-debug.log*
40+
yarn-debug.log*
41+
yarn-error.log*
42+
pnpm-debug.log*
43+
lerna-debug.log*

.github/workflows/ci.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
backend:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Set up Go
15+
uses: actions/setup-go@v5
16+
with:
17+
go-version: '1.24'
18+
- name: Build
19+
run: go build
20+
- name: Test
21+
run: make test
22+
23+
frontend:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
- name: Setup Node.js
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: '22'
31+
cache: 'npm'
32+
cache-dependency-path: ui/package-lock.json
33+
- name: Install dependencies
34+
run: cd ui && npm ci
35+
- name: Lint
36+
run: cd ui && npm run lint
37+
- name: Build
38+
run: cd ui && npm run build
39+
- name: Test
40+
run: cd ui && npm test

.github/workflows/release.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
permissions:
8+
contents: write
9+
packages: write
10+
11+
jobs:
12+
binaries:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
goos: [linux, darwin, windows]
17+
goarch: [amd64, arm64]
18+
steps:
19+
- uses: actions/checkout@v4
20+
- name: Set up Go
21+
uses: actions/setup-go@v5
22+
with:
23+
go-version: '1.24'
24+
- name: Set up Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: '22'
28+
- name: Build
29+
env:
30+
GOOS: ${{ matrix.goos }}
31+
GOARCH: ${{ matrix.goarch }}
32+
BINARY_NAME: mail-sink-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.goos == 'windows' && '.exe' || '' }}
33+
run: |
34+
# Build just the binary without UI
35+
make all BINARY_NAME=${BINARY_NAME} VERSION=${{ github.ref_name }}
36+
- name: Upload Release Asset
37+
uses: softprops/action-gh-release@v1
38+
with:
39+
files: mail-sink-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.goos == 'windows' && '.exe' || '' }}
40+
41+
docker:
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v4
45+
- name: Set up QEMU
46+
uses: docker/setup-qemu-action@v3
47+
- name: Set up Docker Buildx
48+
uses: docker/setup-buildx-action@v3
49+
- name: Login to GitHub Container Registry
50+
uses: docker/login-action@v3
51+
with:
52+
registry: ghcr.io
53+
username: ${{ github.actor }}
54+
password: ${{ secrets.GITHUB_TOKEN }}
55+
- name: Build and push
56+
uses: docker/build-push-action@v5
57+
with:
58+
context: .
59+
platforms: linux/amd64,linux/arm64
60+
push: true
61+
tags: |
62+
ghcr.io/${{ github.repository }}:latest
63+
ghcr.io/${{ github.repository }}:${{ github.ref_name }}

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Binary
2+
mail-sink
3+
4+
# Dependency directories
5+
node_modules/
6+
vendor/
7+
8+
# Build outputs
9+
ui/dist/
10+
11+
# Log files
12+
*.log
13+
14+
# Mac OS
15+
.DS_Store
16+
17+
# Editor files
18+
.vscode/
19+
.idea/
20+
*.swp
21+
*.swo
22+
23+
# Go specific
24+
*.exe
25+
*.exe~
26+
*.dll
27+
*.so
28+
*.dylib
29+
*.test
30+
*.out
31+
go.work
32+
33+
# NPM/Yarn
34+
package-lock.json
35+
yarn.lock

Dockerfile

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
### Build UI stage ###
2+
FROM node:20-slim AS ui-builder
3+
WORKDIR /app/ui
4+
5+
# Copy UI package files first for better caching
6+
COPY ui/package.json ui/package-lock.json* ./
7+
8+
# Install dependencies
9+
RUN npm ci
10+
11+
# Copy UI source files
12+
COPY ui/ ./
13+
14+
# Build UI
15+
RUN npm run build
16+
17+
### Build Go application stage ###
18+
FROM golang:1.24-alpine AS go-builder
19+
WORKDIR /app
20+
21+
# Copy Go module files first for better caching
22+
COPY go.mod go.sum ./
23+
RUN go mod download
24+
25+
# Copy UI build artifacts
26+
COPY --from=ui-builder /app/ui/dist ./ui/dist
27+
28+
# Copy Go source code
29+
COPY . .
30+
31+
# Build Go binary
32+
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o mail-sink .
33+
34+
### Final minimal image ###
35+
FROM alpine:3.19
36+
37+
# Add ca-certificates and timezone info
38+
RUN apk --no-cache add ca-certificates tzdata
39+
40+
# Create non-root user
41+
RUN adduser -D -u 1000 appuser
42+
43+
WORKDIR /app
44+
45+
# Copy binary from builder
46+
COPY --from=go-builder /app/mail-sink .
47+
48+
# Use non-root user
49+
USER appuser
50+
51+
# Expose ports
52+
EXPOSE 1025 8080
53+
54+
# Set default environment variables
55+
ENV SMTP_PORT=1025
56+
ENV HTTP_PORT=8080
57+
ENV GIN_MODE=release
58+
59+
# Run the application
60+
CMD ["/app/mail-sink"]

Makefile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Makefile for Mail Sink
2+
3+
# Binary name
4+
BINARY_NAME=mail-sink
5+
VERSION=$(shell git describe --tags --always)
6+
COMMIT=$(shell git rev-parse --short HEAD)
7+
8+
# Default target
9+
.PHONY: all
10+
all: $(BINARY_NAME)
11+
12+
# Build Go binary (depends on UI being built)
13+
$(BINARY_NAME): main.go go.mod ui/dist
14+
@echo "Building Mail Sink..."
15+
go build -ldflags "-X github.com/recrsn/mail-sink/internal/version.GitCommit=$(COMMIT) -X github.com/recrsn/mail-sink/internal/version.Version=$(VERSION)" -o $(BINARY_NAME)
16+
17+
# UI build - only rebuilds if src files are newer than dist
18+
ui/dist: ui/src/**/* ui/package.json ui/vite.config.ts
19+
@echo "Building UI..."
20+
cd ui && npm install && npm run build
21+
@touch ui/dist
22+
23+
# Clean build artifacts
24+
.PHONY: clean
25+
clean:
26+
@echo "Cleaning up..."
27+
rm -f $(BINARY_NAME)
28+
rm -rf ui/dist
29+
30+
# Run tests
31+
.PHONY: test
32+
test:
33+
@echo "Running tests..."
34+
go test -v ./...
35+
36+
# Help target
37+
.PHONY: help
38+
help:
39+
@echo "Mail Sink Makefile"
40+
@echo ""
41+
@echo "Targets:"
42+
@echo " all - Build the entire application (default)"
43+
@echo " clean - Remove build artifacts"
44+
@echo " test - Run all tests"

README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Mail Sink
2+
3+
A simple SMTP server for testing email flows locally. It provides a REST API to access received emails and includes a web UI.
4+
5+
## Features
6+
7+
- SMTP server that captures all incoming emails
8+
- Parses email content including HTML, plain text, and attachments
9+
- REST API to retrieve emails and clear the mailbox
10+
- Web UI for viewing and managing emails
11+
- Single binary deployment with embedded UI
12+
13+
## Usage
14+
15+
### Building
16+
17+
You can use the provided Makefile to build both the UI and the Go binary in one step:
18+
19+
```bash
20+
# Build everything
21+
make
22+
23+
# Or separately
24+
cd ui
25+
npm install
26+
npm run build
27+
cd ..
28+
go build -o mail-sink
29+
```
30+
31+
### Running
32+
33+
Using the Makefile:
34+
35+
```bash
36+
# Run with default settings
37+
make run
38+
39+
# Run with custom ports
40+
make run-custom SMTP_PORT=2525 HTTP_PORT=3000
41+
```
42+
43+
Or directly:
44+
45+
```bash
46+
# Run with default settings
47+
./mail-sink
48+
49+
# Run with custom ports
50+
./mail-sink --smtp-port 2525 --http-port 3000
51+
```
52+
53+
### Development
54+
55+
To run the UI in development mode with hot reloading:
56+
57+
```bash
58+
# Start the Go server
59+
./mail-sink
60+
61+
# In another terminal, start the UI development server
62+
cd ui
63+
npm run dev
64+
```
65+
66+
This will start the UI development server that proxies API requests to the Go backend.
67+
68+
### Command line options
69+
70+
- `--smtp-port PORT`: SMTP server port (default: 1025)
71+
- `--http-port PORT`: HTTP server port (default: 8080)
72+
- `--help`: Show help
73+
74+
## API
75+
76+
The following API endpoints are available:
77+
78+
- `GET /api/emails`: Get all received emails
79+
- `GET /api/emails/:id`: Get a specific email by ID
80+
- `DELETE /api/emails`: Clear all emails
81+
- `GET /api/info`: Get server information (ports)
82+
83+
## SMTP Configuration
84+
85+
To send emails to the Mail Sink, configure your email client or application with:
86+
87+
- SMTP Server: localhost
88+
- SMTP Port: 1025 (or custom port)
89+
- Authentication: None required (all authentication attempts are accepted)
90+
91+
## License
92+
93+
MIT

0 commit comments

Comments
 (0)