Skip to main content

Email Verification Service with Fiber

Github StackBlitz

A clean architecture based email verification service that generates and validates verification codes.

Features

  • Clean Architecture implementation
  • In-memory verification code storage
  • SMTP email service integration
  • Code generation and hashing
  • Configurable code expiration
  • Thread-safe operations

Project Structure

email-verification/
├── api/
│ └── handlers/ # HTTP handlers
├── application/ # Application business logic
├── domain/ # Domain models and interfaces
├── infrastructure/ # External implementations
│ ├── code/ # Code generation
│ ├── email/ # SMTP service
│ └── repository/ # Data storage
└── config/ # Configuration

Configuration

The application is configured via environment variables. Copy .env.example to .env and fill in your SMTP credentials:

cp .env.example .env
VariableRequiredDefaultDescription
SMTP_HOSTNosmtp.gmail.comSMTP server hostname
SMTP_PORTNo587SMTP server port
SMTP_USERYesSMTP username / email address
SMTP_PASSYesSMTP password or app-password

The application exits with a fatal error on startup if SMTP_USER or SMTP_PASS are not set.

API Endpoints

MethodURLDescription
POST/verify/send/:emailSend verification code
POST/verify/check/:email/:codeVerify the received code

Example Usage

  1. Send verification code:
curl -X POST http://localhost:3000/verify/send/[email protected]
  1. Verify code:
curl -X POST http://localhost:3000/verify/check/[email protected]/123456

Response Examples

Success:

{
"message": "Code verified successfully"
}

Error:

{
"error": "invalid code"
}

How to Run

  1. Copy .env.example to .env and set your SMTP credentials.
  2. Export the environment variables and run the application:
export $(cat .env | xargs)
go run main.go

Dependencies