Prerequisites
Before deploying the backend, ensure you have:- Go 1.23.6 or later installed
- PostgreSQL database (Supabase recommended)
- Access to a server with TCP port availability
- Git installed for cloning the repository
Installation
Install dependencies
Download the required Go modules:The backend uses these dependencies:
github.com/lib/pq- PostgreSQL drivergithub.com/joho/godotenv- Environment variable management
Configure environment variables
Create a Add the required environment variables:
.env file in the backend directory:The
PORT variable determines which port the SMTP server listens on. The SUPABASE_CONN_STRING is your PostgreSQL connection string.Running the server
Database setup
The backend requires a PostgreSQL database with the following table schema:Server features
SMTP command support
The server implements the following SMTP commands (backend/main.go:92-159):HELO/EHLO- Initiate connectionMAIL FROM- Specify senderRCPT TO- Specify recipientDATA- Send email contentQUIT- Close connectionNOOP- No operationVRFY- Verify address (returns not supported)EXPN- Expand mailing list (returns not supported)HELP- Display supported commands
Automatic cleanup
The server runs an automatic cleanup job every hour that deletes emails older than 7 days (backend/main.go:196-208):Testing the SMTP server
You can test the server using telnet:Deployment options
Troubleshooting
Connection refused
If you can’t connect to the SMTP server:- Verify the
PORTenvironment variable is set correctly - Check firewall rules allow incoming connections on the specified port
- Ensure the server is running and listening
Database connection errors
If you see database connection errors:- Verify
SUPABASE_CONN_STRINGis correct - Test the connection string directly with
psql - Check database credentials and network access
- Ensure the
emailstable exists
The server will log “No .env file found” if no
.env file exists, but will continue if environment variables are set through other means (e.g., system environment variables).Next steps
Frontend setup
Deploy the Next.js web interface to complete your Zapmail installation