codeword/internal/adapters/client/mail.go
2023-12-31 15:22:03 +03:00

37 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package client
import (
"fmt"
"net/smtp"
)
type RecoveryEmailSender struct {
SmtpHost string
SmtpPort string
Username string
Password string
ApiKey string
}
// SendRecoveryEmail отправляет email с подписью для восстановления доступа
func (r *RecoveryEmailSender) SendRecoveryEmail(email, signature string) error {
// прост как пример пока что
message := fmt.Sprintf("To: %s\r\n"+
"Subject: Восстановление доступа\r\n"+
"\r\n"+
"Чтобы восстановить доступ, пожалуйста, перейдите по ссылке ниже:\r\n"+
" https://hub.pena.digital/codeword/restore/%s\r\n", email, signature)
auth := smtp.PlainAuth("", r.Username, r.Password, r.SmtpHost)
err := smtp.SendMail(r.SmtpHost+":"+r.SmtpPort, auth, r.Username, []string{email}, []byte(message))
if err != nil {
fmt.Printf("Ошибка при отправке письма: %s\n", err)
return err
}
fmt.Printf("Письмо для восстановления доступа отправлено на: %s\n", email)
return nil
}