2024-06-11 18:50:35 +00:00
|
|
|
package senders
|
|
|
|
|
2024-06-24 15:46:00 +00:00
|
|
|
import (
|
|
|
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/clients"
|
|
|
|
)
|
2024-06-11 18:50:35 +00:00
|
|
|
|
|
|
|
type MailLeadSender struct {
|
|
|
|
client *clients.SmtpClient
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMailLeadSender(client *clients.SmtpClient) *MailLeadSender {
|
|
|
|
return &MailLeadSender{client: client}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MailLeadSender) SendLead(data LeadData) error {
|
2024-06-24 15:46:00 +00:00
|
|
|
err := m.SendMailWithAttachment(data.To.(string), data.Subject, data.Template, data.TemplateData, nil)
|
2024-06-11 18:50:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MailLeadSender) SendMailWithAttachment(recipient, subject string, emailTemplate string, data TemplateData, attachments []clients.Attachment) error {
|
2024-06-24 10:31:08 +00:00
|
|
|
sanitizedData := sanitizeHTMLData(data)
|
|
|
|
text, err := generateTextFromTemplate(sanitizedData, emailTemplate)
|
2024-06-11 18:50:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
msg := clients.Message{
|
|
|
|
To: recipient,
|
|
|
|
Subject: subject,
|
|
|
|
HtmlBody: text,
|
|
|
|
Attachments: attachments,
|
|
|
|
}
|
|
|
|
|
|
|
|
return m.client.MailSender(msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MailLeadSender) Name() string {
|
|
|
|
return "mail"
|
|
|
|
}
|