diff --git a/bot/command.go b/bot/command.go index 87341ca..9aa3925 100644 --- a/bot/command.go +++ b/bot/command.go @@ -283,7 +283,24 @@ func (b *Bot) runSend(ctx context.Context, commandSlice []string) { return } - err = b.Send2Email(ctx, to, subject, body) + cfg, err := b.getRoomSettings(evt.RoomID) + if err != nil { + b.Error(ctx, evt.RoomID, "failed to retrieve room settings: %v", err) + return + } + + mailbox := cfg.Mailbox() + if mailbox == "" { + b.SendNotice(ctx, evt.RoomID, "mailbox is not configured, kupo") + return + } + + from := mailbox + "@" + b.domain + ID := evt.ID.String()[1:] + "@" + b.domain + data := utils. + NewEmail(ID, "", subject, from, to, body, "", nil). + Compose(b.getBotSettings().DKIMPrivateKey()) + err = b.mta.Send(from, to, data) if err != nil { b.Error(ctx, evt.RoomID, "cannot send email: %v", err) return diff --git a/bot/email.go b/bot/email.go index d3c015d..10f1a84 100644 --- a/bot/email.go +++ b/bot/email.go @@ -121,6 +121,7 @@ func (b *Bot) getParentEmail(evt *event.Event) (string, string, string) { } // Send2Email sends message to email +// TODO rewrite to thread replies only func (b *Bot) Send2Email(ctx context.Context, to, subject, body string) error { var inReplyTo string evt := eventFromContext(ctx)