mirror of
https://github.com/absmach/magistrala.git
synced 2026-08-07 07:14:46 +00:00
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
Signed-off-by: dusan <borovcanindusan1@gmail.com>
41 lines
1.1 KiB
Go
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 ¬ifier{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{})
|
|
}
|