This is the main dovel repository, it has the Go code to run dovel SMTP server.
- package main
- import (
- "encoding/json"
- "os"
- )
- // Config is used to configure your email server.
- // Port is used to specify which port the server should listen
- // to connections, a typicall value is 2525.
- // Domain is what the server should respond in a HELO or EHLO request.
- // VaultFile is the path to a json file containing the list of users
- // that can send email.
- // In order to use TLS connections Certficate and PrivateKey fields
- // must have valid path to pem encoded keys.
- type Config struct {
- Port string
- Domain string
- Certificate string
- PrivateKey string
- VaultFile string
- ReadTimeout int
- WriteTimeout int
- MaxMessageBytes int64
- MaxRecipients int
- AllowInsecureAuth bool
- }
- // Vault interface gives validation and user fetching.
- type Vault interface {
- Validate(n, p string) bool
- GetUser(n string) User
- }
- // User represents a user that should be able to send emails. This struct is
- // found in the users json file, that is on the path pointed by VaultFile field
- // in [Config].
- type User struct {
- Name string
- Email string
- Password string
- }
- type store struct {
- users []User
- }
- func NewStore(path string) (Vault, error) {
- f, err := os.Open(path)
- if err != nil {
- return nil, err
- }
- s := store{users: []User{}}
- json.NewDecoder(f).Decode(&s.users)
- return s, err
- }
- func (s store) Validate(n, p string) bool {
- u := s.GetUser(n)
- return u.Password == p
- }
- func (s store) GetUser(n string) User {
- for _, u := range s.users {
- if u.Name == n {
- return u
- }
- }
- return User{}
- }