email

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 4, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Send

func Send(req Request, cfg config.Config) error

Send is a package-level function that uses the default email service This is for backward compatibility

Types

type MockSMTPClient

type MockSMTPClient struct {
	DialFunc  func(addr string) (SMTPClient, error)
	MailFunc  func(from string) error
	RcptFunc  func(to string) error
	DataFunc  func() (io.WriteCloser, error)
	QuitFunc  func() error
	CloseFunc func() error
	AuthFunc  func(auth smtp.Auth) error
}

MockSMTPClient implements a mock SMTP client for testing

func (*MockSMTPClient) Auth

func (m *MockSMTPClient) Auth(auth smtp.Auth) error

Auth is a mock implementation of smtp.Client.Auth

func (*MockSMTPClient) Close

func (m *MockSMTPClient) Close() error

Close is a mock implementation of smtp.Client.Close

func (*MockSMTPClient) Data

func (m *MockSMTPClient) Data() (io.WriteCloser, error)

Data is a mock implementation of smtp.Client.Data

func (*MockSMTPClient) Dial

func (m *MockSMTPClient) Dial(addr string) (SMTPClient, error)

Dial is a mock implementation of net/smtp.Dial

func (*MockSMTPClient) Mail

func (m *MockSMTPClient) Mail(from string) error

Mail is a mock implementation of smtp.Client.Mail

func (*MockSMTPClient) Quit

func (m *MockSMTPClient) Quit() error

Quit is a mock implementation of smtp.Client.Quit

func (*MockSMTPClient) Rcpt

func (m *MockSMTPClient) Rcpt(to string) error

Rcpt is a mock implementation of smtp.Client.Rcpt

type MockWriteCloser

type MockWriteCloser struct {
	WriteFunc func(p []byte) (n int, err error)
	CloseFunc func() error
	Data      []byte
}

MockWriteCloser implements a mock for io.WriteCloser

func (*MockWriteCloser) Close

func (m *MockWriteCloser) Close() error

Close is a mock implementation of io.Closer.Close

func (*MockWriteCloser) Write

func (m *MockWriteCloser) Write(p []byte) (n int, err error)

Write is a mock implementation of io.Writer.Write

type Request

type Request struct {
	From    string `json:"from"`
	To      string `json:"to"`
	Subject string `json:"subject"`
	Body    string `json:"body"`
	HTML    bool   `json:"html"`
}

Request represents an incoming request to send an email

type SMTPClient

type SMTPClient interface {
	Mail(from string) error
	Rcpt(to string) error
	Data() (io.WriteCloser, error)
	Quit() error
	Close() error
	Auth(auth smtp.Auth) error
}

SMTPClient defines the interface for SMTP operations This allows us to mock the SMTP client for testing

type SMTPDialer

type SMTPDialer func(addr string) (SMTPClient, error)

SMTPDialer is a function type for creating SMTP clients

var DefaultSMTPDialer SMTPDialer = defaultSMTPDialFn

DefaultSMTPDialer is the default dialer that can be replaced for testing

type Service

type Service interface {
	Send(req Request, cfg config.Config) error
}

Service defines the operations for sending emails

type ServiceImpl

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

ServiceImpl implements the Service interface

func NewService

func NewService(dialer SMTPDialer) *ServiceImpl

NewService creates a new email service with the given SMTP dialer

func (*ServiceImpl) Send

func (s *ServiceImpl) Send(req Request, cfg config.Config) error

Send handles sending an email using the configured SMTP server

Jump to

Keyboard shortcuts

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