send emails to multiple addresses at once
This commit is contained in:
@@ -33,7 +33,7 @@ so you can use it to send emails from your apps and scripts as well.
|
|||||||
|
|
||||||
- [x] SMTP client
|
- [x] SMTP client
|
||||||
- [x] SMTP server (you can use Postmoogle as general purpose SMTP server to send emails from your scripts or apps)
|
- [x] SMTP server (you can use Postmoogle as general purpose SMTP server to send emails from your scripts or apps)
|
||||||
- [x] Send a message to matrix room with special format to send a new email
|
- [x] Send a message to matrix room with special format to send a new email, even to multiple email addresses at once
|
||||||
- [ ] Reply to matrix thread sends reply into email thread
|
- [ ] Reply to matrix thread sends reply into email thread
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|||||||
@@ -337,11 +337,6 @@ func (b *Bot) runSend(ctx context.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !utils.AddressValid(to) {
|
|
||||||
b.Error(ctx, evt.RoomID, "email address is not valid")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
cfg, err := b.getRoomSettings(evt.RoomID)
|
cfg, err := b.getRoomSettings(evt.RoomID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Error(ctx, evt.RoomID, "failed to retrieve room settings: %v", err)
|
b.Error(ctx, evt.RoomID, "failed to retrieve room settings: %v", err)
|
||||||
@@ -354,16 +349,29 @@ func (b *Bot) runSend(ctx context.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
from := mailbox + "@" + b.domain
|
tos := strings.Split(to, ",")
|
||||||
ID := fmt.Sprintf("<%s@%s>", evt.ID, b.domain)
|
// validate first
|
||||||
data := utils.
|
for _, to := range tos {
|
||||||
NewEmail(ID, "", subject, from, to, body, "", nil).
|
if !utils.AddressValid(to) {
|
||||||
Compose(b.getBotSettings().DKIMPrivateKey())
|
b.Error(ctx, evt.RoomID, "email address is not valid")
|
||||||
err = b.mta.Send(from, to, data)
|
return
|
||||||
if err != nil {
|
}
|
||||||
b.Error(ctx, evt.RoomID, "cannot send email: %v", err)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
b.SendNotice(ctx, evt.RoomID, "Email has been sent")
|
from := mailbox + "@" + b.domain
|
||||||
|
ID := fmt.Sprintf("<%s@%s>", evt.ID, b.domain)
|
||||||
|
for _, to := range tos {
|
||||||
|
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 to %s: %v", to, err)
|
||||||
|
} else {
|
||||||
|
b.SendNotice(ctx, evt.RoomID, "Email has been sent to "+to)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(tos) > 1 {
|
||||||
|
b.SendNotice(ctx, evt.RoomID, "All emails were sent.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user