Allow email relaying to a real MTA
This commit is contained in:
@ -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),
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user