integrated rabbitmq
parent
2e6cbef3e1
commit
0e25f2b407
17
main.go
17
main.go
|
@ -4,7 +4,6 @@ import (
|
|||
"clickandjoin.app/emailserver/mailer"
|
||||
"clickandjoin.app/emailserver/modules/config"
|
||||
"clickandjoin.app/emailserver/modules/rabbitmq"
|
||||
"clickandjoin.app/emailserver/modules/structs"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
@ -17,23 +16,9 @@ func init() {
|
|||
|
||||
logrus.Println("Debug:", config.Cfg.Debug)
|
||||
|
||||
rabbitmq.Init()
|
||||
|
||||
mailer.Init()
|
||||
}
|
||||
|
||||
func main() {
|
||||
logrus.Println("test")
|
||||
|
||||
test := struct {
|
||||
Url string
|
||||
Username string
|
||||
ActivationCode string
|
||||
}{
|
||||
Url: "https://test.de",
|
||||
Username: "Ben",
|
||||
ActivationCode: "912 211",
|
||||
}
|
||||
|
||||
mailer.NewMail(structs.Mail{To: []string{"info@clickandjoin.de"}, TemplateId: "emailVerification", LanguageId: "de", BodyData: test})
|
||||
rabbitmq.Init()
|
||||
}
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package rabbitmq
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"clickandjoin.app/emailserver/mailer"
|
||||
"clickandjoin.app/emailserver/modules/config"
|
||||
"clickandjoin.app/emailserver/modules/structs"
|
||||
amqp "github.com/rabbitmq/amqp091-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
@ -62,7 +65,27 @@ func Init() {
|
|||
|
||||
go func() {
|
||||
for d := range msgs {
|
||||
logrus.Printf("Received a message: %s", d.Body)
|
||||
logrus.Debugln("RECV MAIL")
|
||||
|
||||
mailMessage := structs.RabbitMqMailMessage{}
|
||||
|
||||
if err := json.Unmarshal(d.Body, &mailMessage); err != nil {
|
||||
logrus.Errorln("Failed to unmarshal json message, err:", err)
|
||||
continue
|
||||
}
|
||||
|
||||
err = mailer.NewMail(structs.Mail{
|
||||
To: []string{"info@clickandjoin.de"},
|
||||
TemplateId: mailMessage.TemplateId,
|
||||
LanguageId: mailMessage.LanguageId,
|
||||
BodyData: mailMessage.BodyData})
|
||||
|
||||
if err != nil {
|
||||
logrus.Errorln("Failed to send new mail, err:", err)
|
||||
continue
|
||||
}
|
||||
|
||||
d.Ack(false)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
@ -5,3 +5,10 @@ type RabbitMqMessage struct {
|
|||
Rec string
|
||||
Body any
|
||||
}
|
||||
|
||||
type RabbitMqMailMessage struct {
|
||||
UserMail string `json:"m"`
|
||||
TemplateId string `json:"t"`
|
||||
LanguageId string `json:"l"`
|
||||
BodyData map[string]interface{} `json:"b"`
|
||||
}
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
<body>
|
||||
<h1>%header%</h1>
|
||||
<p>%informationText%</p>
|
||||
<p>{{.ActivationCode}}</p>
|
||||
<p><b>{{.activation_code}}</b></p>
|
||||
|
||||
<a
|
||||
href="{{.Url}}"
|
||||
href="{{.url}}"
|
||||
style="
|
||||
padding: 8px 20px;
|
||||
background-color: #4b72fa;
|
||||
|
@ -21,6 +21,6 @@
|
|||
>%buttonText%</a
|
||||
>
|
||||
|
||||
<p>%alternativeUrl% <a href="{{.Url}}">{{.Url}}</a></p>
|
||||
<p>%alternativeUrl% <a href="{{.url}}">{{.url}}</a></p>
|
||||
</body>
|
||||
</html>
|
|
@ -6,8 +6,8 @@
|
|||
"de": "Ihr E-Mail-Bestätigungscode"
|
||||
},
|
||||
"header": {
|
||||
"en": "Hello {{.Username}}",
|
||||
"de": "Hallo {{.Username}},"
|
||||
"en": "Good day,",
|
||||
"de": "Guten Tag,"
|
||||
},
|
||||
"informationText": {
|
||||
"en": "to confirm your identity we need to verify your email.",
|
||||
|
|
Loading…
Reference in New Issue