Skip to content

Latest commit

Β 

History

History
99 lines (77 loc) Β· 2.54 KB

File metadata and controls

99 lines (77 loc) Β· 2.54 KB
title keywords description
Email Verification Service
email
verification
smtp
golang
fiber
Email verification service with code generation and validation

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

Update config/config.go with your SMTP settings:

func GetConfig() *Config {
    return &Config{
        SMTPHost:       "smtp.gmail.com",
        SMTPPort:       587,
        SMTPUser:       "your-email@gmail.com",
        SMTPPassword:   "your-app-password",
        CodeExpiration: time.Minute * 1,
    }
}

API Endpoints

Method URL Description
POST /verify/send/:email Send verification code
POST /verify/check/:email/:code Verify the received code

Example Usage

  1. Send verification code:
curl -X POST http://localhost:3000/verify/send/user@example.com
  1. Verify code:
curl -X POST http://localhost:3000/verify/check/user@example.com/123456

Response Examples

Success:

{
    "message": "Code verified successfully"
}

Error:

{
    "error": "invalid code"
}

How to Run

  1. Configure SMTP settings in config/config.go
  2. Run the application:
go run main.go

Dependencies