list

server

This is the main dovel repository, it has the Go code to run dovel SMTP server.

curl -O https://dovel.email/server.tar.gz tar.gz

model.go

  1. package main
  2. import (
  3. "encoding/json"
  4. "os"
  5. )
  6. // Config is used to configure your email server.
  7. // Port is used to specify which port the server should listen
  8. // to connections, a typicall value is 2525.
  9. // Domain is what the server should respond in a HELO or EHLO request.
  10. // VaultFile is the path to a json file containing the list of users
  11. // that can send email.
  12. // In order to use TLS connections Certficate and PrivateKey fields
  13. // must have valid path to pem encoded keys.
  14. type Config struct {
  15. Port string
  16. Domain string
  17. Certificate string
  18. PrivateKey string
  19. VaultFile string
  20. ReadTimeout int
  21. WriteTimeout int
  22. MaxMessageBytes int64
  23. MaxRecipients int
  24. AllowInsecureAuth bool
  25. }
  26. // Vault interface gives validation and user fetching.
  27. type Vault interface {
  28. Validate(n, p string) bool
  29. GetUser(n string) User
  30. }
  31. // User represents a user that should be able to send emails. This struct is
  32. // found in the users json file, that is on the path pointed by VaultFile field
  33. // in [Config].
  34. type User struct {
  35. Name string
  36. Email string
  37. Password string
  38. }
  39. type store struct {
  40. users []User
  41. }
  42. func NewStore(path string) (Vault, error) {
  43. f, err := os.Open(path)
  44. if err != nil {
  45. return nil, err
  46. }
  47. s := store{users: []User{}}
  48. json.NewDecoder(f).Decode(&s.users)
  49. return s, err
  50. }
  51. func (s store) Validate(n, p string) bool {
  52. u := s.GetUser(n)
  53. return u.Password == p
  54. }
  55. func (s store) GetUser(n string) User {
  56. for _, u := range s.users {
  57. if u.Name == n {
  58. return u
  59. }
  60. }
  61. return User{}
  62. }