smtp

package
v0.0.0-...-449d51e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SMTPConfig

type SMTPConfig struct {
	FromName     string
	FromAddress  string
	SMTPUsername string
	SMTPPassword string
	SMTPServer   string
	SMTPPort     int
	TestAPIPort  int
}

SMTPConfig represents the configuration for the SMTP email service. It contains the sender's name, address, SMTP username, password, server and port. The TestAPIPort is used to define the port of the API service used for testing the email service locally to check messages (for example using MailHog).

type SMTPEmail

type SMTPEmail struct {
	// contains filtered or unexported fields
}

SMTPEmail is the implementation of the NotificationService interface for the SMTP email service. It contains the configuration and the SMTP auth. It uses the net/smtp package to send emails.

func (*SMTPEmail) FindEmail

func (sm *SMTPEmail) FindEmail(ctx context.Context, to string) (string, error)

FindEmail searches for an email in the test API service. It sends a GET request to the search endpoint with the recipient's email address as a query parameter. If the email is found, it returns the email body and clears the inbox. If the email is not found, it returns an EOF error. If the request fails, it returns an error with the status code. This method is used for testing the email service.

func (*SMTPEmail) New

func (se *SMTPEmail) New(rawConfig any) error

New initializes the SMTP email service with the configuration. It sets the SMTP auth if the username and password are provided. It returns an error if the configuration is invalid or if the from email could not be parsed.

func (*SMTPEmail) SendNotification

func (se *SMTPEmail) SendNotification(ctx context.Context, notification *notifications.Notification) error

SendNotification sends an email notification to the recipient. It composes the email body with the notification data and sends it using the SMTP server.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL