move email sending to b.runSend()
This commit is contained in:
@@ -283,7 +283,24 @@ func (b *Bot) runSend(ctx context.Context, commandSlice []string) {
|
|||||||
return
|
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 {
|
if err != nil {
|
||||||
b.Error(ctx, evt.RoomID, "cannot send email: %v", err)
|
b.Error(ctx, evt.RoomID, "cannot send email: %v", err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ func (b *Bot) getParentEmail(evt *event.Event) (string, string, string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send2Email sends message to email
|
// Send2Email sends message to email
|
||||||
|
// TODO rewrite to thread replies only
|
||||||
func (b *Bot) Send2Email(ctx context.Context, to, subject, body string) error {
|
func (b *Bot) Send2Email(ctx context.Context, to, subject, body string) error {
|
||||||
var inReplyTo string
|
var inReplyTo string
|
||||||
evt := eventFromContext(ctx)
|
evt := eventFromContext(ctx)
|
||||||
|
|||||||
Reference in New Issue
Block a user