notification serviceda email xabar yuborish qo'shildi
This commit is contained in:
5
internal/domain/email.go
Normal file
5
internal/domain/email.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package domain
|
||||
|
||||
type EmailServicePort interface {
|
||||
SendMail([]string, []byte)
|
||||
}
|
||||
@@ -2,15 +2,19 @@ package notifier
|
||||
|
||||
import (
|
||||
"github.com/JscorpTech/notification/internal/domain"
|
||||
"github.com/k0kubun/pp/v3"
|
||||
"github.com/JscorpTech/notification/internal/services"
|
||||
)
|
||||
|
||||
type emailNotifier struct{}
|
||||
type emailNotifier struct {
|
||||
EmailService domain.EmailServicePort
|
||||
}
|
||||
|
||||
func NewEmailNotifier() domain.NotifierPort {
|
||||
return &emailNotifier{}
|
||||
return &emailNotifier{
|
||||
EmailService: services.NewEmailService(),
|
||||
}
|
||||
}
|
||||
|
||||
func (n *emailNotifier) SendMessage(to []string, body string) {
|
||||
pp.Print(to, body)
|
||||
n.EmailService.SendMail(to, []byte(body))
|
||||
}
|
||||
|
||||
33
internal/services/email.go
Normal file
33
internal/services/email.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/smtp"
|
||||
"os"
|
||||
|
||||
"github.com/JscorpTech/notification/internal/domain"
|
||||
)
|
||||
|
||||
type emailService struct{}
|
||||
|
||||
func NewEmailService() domain.EmailServicePort {
|
||||
return &emailService{}
|
||||
}
|
||||
|
||||
func (e *emailService) SendMail(to []string, body []byte) {
|
||||
// Gmail konfiguratsiyasi
|
||||
from := os.Getenv("MAIL_USER")
|
||||
password := os.Getenv("MAIL_PASSWORD")
|
||||
smtpHost := os.Getenv("MAIL_DOMAIN")
|
||||
smtpPort := os.Getenv("MAIL_PORT")
|
||||
|
||||
auth := smtp.PlainAuth("", from, password, smtpHost)
|
||||
|
||||
err := smtp.SendMail(smtpHost+":"+smtpPort, auth, from, to, body)
|
||||
if err != nil {
|
||||
fmt.Println("Xatolik:", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Email yuborildi!")
|
||||
}
|
||||
Reference in New Issue
Block a user