Files
magistrala/consumers/notifiers/smtp/notifier.go
T
Dušan Borovčanin 168e8b90cb
Property Based Tests / api-test (push) Has been cancelled
Continuous Delivery / lint-and-build (push) Has been cancelled
Deploy GitHub Pages / swagger-ui (push) Has been cancelled
CI Pipeline / Lint Proto (push) Has been cancelled
CI Pipeline / Detect Changes (push) Has been cancelled
Continuous Delivery / Build and Push Docker Images (push) Has been cancelled
CI Pipeline / lint-and-build (push) Has been cancelled
CI Pipeline / Test ${{ matrix.module }} (push) Has been cancelled
CI Pipeline / Upload Coverage (push) Has been cancelled
NOISSUE - Move rules engine, alarms, reports, journal and notifications to EE (#3552)
Signed-off-by: dusan <borovcanindusan1@gmail.com>
2026-07-30 17:55:57 +02:00

41 lines
1.1 KiB
Go

// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0
package smtp
import (
"fmt"
"github.com/absmach/magistrala/consumers"
"github.com/absmach/magistrala/pkg/email"
"github.com/absmach/magistrala/pkg/messaging"
)
const (
footer = "Sent by Magistrala SMTP Notification"
contentTemplate = "A publisher with an id %s sent the message over %s with the following values \n %s"
)
var _ consumers.Notifier = (*notifier)(nil)
type notifier struct {
agent *email.Agent
}
// New instantiates SMTP message notifier.
func New(agent *email.Agent) consumers.Notifier {
return &notifier{agent: agent}
}
func (n *notifier) Notify(from string, to []string, msg *messaging.Message) error {
subject := fmt.Sprintf(`Notification for Channel %s`, msg.GetChannel())
if msg.GetSubtopic() != "" {
subject = fmt.Sprintf("%s and subtopic %s", subject, msg.GetSubtopic())
}
values := string(msg.GetPayload())
content := fmt.Sprintf(contentTemplate, msg.GetPublisher(), msg.GetProtocol(), values)
return n.agent.Send(to, from, subject, "", "", content, footer, map[string][]byte{})
}