email

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

README

Email Service

This package provides email functionality for the CertAuth application, specifically for sending verification emails.

Features

  • Email Validation: Validates email format before sending
  • Template-based Emails: Uses Go templates for email content
  • SMTP Support: Configurable SMTP settings
  • Development Mode: Logs emails instead of sending when no SMTP credentials are provided
  • HTML Emails: Sends beautifully formatted HTML emails

Usage

Basic Usage
import "github.com/evidenceledger/certauth/internal/email"

// Create email service
emailService := email.NewService()

// Send verification email
err := emailService.SendVerificationEmail("user@example.com", "123456")
if err != nil {
    // Handle error
}
Configuration

The email service is configured via environment variables:

  • SMTP_HOST: SMTP server hostname (default: "localhost")
  • SMTP_PORT: SMTP server port (default: "587")
  • SMTP_USERNAME: SMTP username (required for production)
  • SMTP_PASSWORD: SMTP password (required for production)
  • FROM_EMAIL: Sender email address (default: "noreply@certauth.mycredential.eu")
  • FROM_NAME: Sender name (default: "CertAuth")
Development Mode

When SMTP_USERNAME and SMTP_PASSWORD are not set, the service runs in development mode and logs emails instead of sending them:

time=2025-09-01T18:55:41.666Z level=INFO msg="Email would be sent (development mode)" to=test@example.com subject="Email Verification Required - CertAuth" body_length=3718
Email Template

The verification email template includes:

  • Verification Code: Large, easy-to-read 6-digit code
  • Expiration Time: Shows when the code expires
  • Security Information: Important security notices
  • Professional Design: Clean, responsive HTML layout
Template Variables

The email template accepts the following variables:

  • {{.VerificationCode}}: The 6-digit verification code
  • {{.ExpiresAt}}: Time when the code expires
  • {{.AppName}}: Application name (default: "CertAuth")

Testing

Run the tests with:

go test ./internal/email/...

Example Email Output

The service generates professional HTML emails with:

  • Responsive design that works on mobile and desktop
  • Clear verification code display
  • Security warnings and instructions
  • Professional branding
  • Accessibility considerations

Documentation

Overview

Package email provides functionality for sending emails using SMTP, including template-based email generation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EmailConfig

type EmailConfig struct {
	User     string `yaml:"user"`
	Password string `yaml:"password"`
	Email    string `yaml:"email"`
	IMAP     string `yaml:"imap"`
	SMTP     string `yaml:"smtp"`
	SMTPPort string `yaml:"smtp_port"`
}

type EmailData

type EmailData struct {
	VerificationCode string
	ExpiresAt        time.Time
	AppName          string
}

EmailData represents the data passed to email templates

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service represents an email service

func NewService

func NewService(cfg *EmailConfig) (*Service, error)

NewService creates a new email service

func (*Service) SendVerificationEmail

func (s *Service) SendVerificationEmail(toEmail string, verificationCode string) error

SendVerificationEmail sends a verification email with a code

func (*Service) ValidateEmail

func (s *Service) ValidateEmail(email string) error

ValidateEmail validates email format

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL