Allow email relaying to a real MTA

This commit is contained in:
2020-11-05 19:48:18 +01:00
parent 9035280818
commit 62344993f5
7 changed files with 213 additions and 8 deletions

View File

@ -53,6 +53,11 @@ func getServiceContainer(conf *config.Config) (*service.Container, error) {
cqrs.CommandHandlerFunc(command.HandleDeleteEmail),
)
bus.RegisterCommand(
cqrs.MatchCommandRequest(&command.RelayEmailRequest{}),
cqrs.CommandHandlerFunc(command.HandleRelayEmail),
)
bus.RegisterQuery(
cqrs.MatchQueryRequest(&query.GetInboxRequest{}),
cqrs.QueryHandlerFunc(query.HandleGetInbox),

View File

@ -12,6 +12,7 @@ import (
"github.com/jhillyerd/enmime"
"github.com/pkg/errors"
"gitlab.com/wpetit/goweb/cqrs"
"gitlab.com/wpetit/goweb/logger"
"gitlab.com/wpetit/goweb/middleware/container"
"gitlab.com/wpetit/goweb/service"
)
@ -74,12 +75,31 @@ func (s *Session) Data(r io.Reader) error {
return errors.Wrap(err, "could not retrieve cqrs service")
}
conf, err := config.From(s.ctn)
if err != nil {
return errors.Wrap(err, "could not retrieve config service")
}
if conf.Relay.Enabled {
cmd := &command.RelayEmailRequest{
Envelope: env,
}
if _, err := bus.Exec(s.ctx, cmd); err != nil {
logger.Error(s.ctx, "could not exec command", logger.E(err))
return errors.Wrapf(err, "could not exec '%T' command", cmd)
}
}
cmd := &command.StoreEmailRequest{
Envelope: env,
}
if _, err := bus.Exec(s.ctx, cmd); err != nil {
return errors.Wrap(err, "could not exec command")
logger.Error(s.ctx, "could not exec command", logger.E(err))
return errors.Wrapf(err, "could not exec '%T' command", cmd)
}
return nil