feat: SendRaw

This commit is contained in:
2025-05-29 09:34:24 +02:00
parent b57eb95497
commit e04ed76fee
3 changed files with 24 additions and 9 deletions

View File

@@ -31,13 +31,19 @@ type SecureConfig struct {
From string // Sender email address
}
type EmailMessage struct {
type MessageWithAttachments struct {
To string
Subject string
Body string
Attachments []EmailAttachment
}
type RawMessage struct {
To string
Subject string
Body string
}
type SMTPClientIface interface {
StartTLS(*tls.Config) error
Auth(a smtp.Auth) error
@@ -205,7 +211,7 @@ func dialTLS(hostPort string, tlsConfig *tls.Config) (SMTPClientIface, error) {
return c, nil
}
func (e *EmailService) SendEmail(emailData EmailMessage) error {
func (e *EmailService) SendEmail(emailData MessageWithAttachments) error {
msg, err := newMessage(e.from, emailData.To, emailData.Subject).
withAttachments(emailData.Body, emailData.Attachments)
@@ -221,6 +227,15 @@ func (e *EmailService) SendEmail(emailData EmailMessage) error {
}
}
func (e *EmailService) SendRaw(emailData RawMessage) error {
switch e.port {
case "465":
return e.sendTLS(emailData.To, []byte(emailData.Body))
default:
return e.send(emailData.To, []byte(emailData.Body))
}
}
func (e *EmailService) send(to string, msg []byte) error {
c, err := e.dial(e.host + ":" + e.port)
if err != nil {