sender

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: BSD-3-Clause Imports: 10 Imported by: 3

README

gomail-sender

Package sender provides a common interface for creating new aaronland/gomail/v2 instances using a URI-based syntax.

Documentation

Go Reference

Example

import (
	"context"
	"github.com/aaronland/gomail/v2"		
)

func main(){

	ctx := context.Background()
	s, _ := NewSender(ctx, "stdout://")

	msg := gomail.NewMessage()
	msg.SetBody("text/plain", "Hello world.")
	msg.SetHeader("From", "from@example.com")
	msg.SetHeader("To", "to@example.com")
	msg.SetHeader("Subject", "Stdout sender")
	
	gomail.Send(s, msg)
}

Error handling removed for the sake of brevity.

See also

Documentation

Overview

Package sender provides a common interface for creating new aaronland/gomail/v2 instances using a URI-based syntax.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewNullSender

func NewNullSender(ctx context.Context, uri string) (gomail.Sender, error)

NewNullSender returns a new `NullSender` instance for delivery messages to nowhere, configured by 'uri' which is expected to take the form of:

$> null://

func NewSMTPSender

func NewSMTPSender(ctx context.Context, uri string) (gomail.Sender, error)

NewSMTPSender returns a new `gomail.Sender` instance for delivery mail to a SMTP endpoint. 'uri' is expecteed to take the form of:

smtp://{HOST}?port={PORT}&username={USERNAME}&password={PASSWORD}

Where ${HOST} is the name of the SMTP server host; {PORT} is the name of the SMTP server port; {USERNAME} and {PASSWORD} are the authentication credentials for accessing the SMTP server.

func NewSender

func NewSender(ctx context.Context, uri string) (gomail.Sender, error)

Create a new instance of the Sender interface. Sender instances are created by passing in a context.Context instance and a URI string. The form and substance of URI strings are specific to their implementations.

func NewStdoutSender

func NewStdoutSender(ctx context.Context, uri string) (gomail.Sender, error)

NewStdoutSender returns a new `NullSender` instance for delivery messages to STDOUT, configured by 'uri' which is expected to take the form of:

$> stdout://

func RegisterSender

func RegisterSender(ctx context.Context, scheme string, f SenderInitializeFunc) error

Register a new URI scheme and SenderInitializeFunc function for a implementation of the Sender interface.

func Schemes

func Schemes() []string

Return a list of URI schemes for registered implementations of the Sender interface.

Types

type NullSender

type NullSender struct {
	gomail.Sender
}

NullSender implements the `gomail.Sender` inferface for delivery messages to nowhere.

func (*NullSender) Send

func (s *NullSender) Send(from string, to []string, msg io.WriterTo) error

Send will copy 'msg' to a `io.Discard` instance.

type SenderInitializeFunc

type SenderInitializeFunc func(context.Context, string) (gomail.Sender, error)

The initialization function signature for implementation of the Sender interface.

type StdoutSender

type StdoutSender struct {
	gomail.Sender
}

NullSender implements the `gomail.Sender` inferface for delivery messages to STDOUT.

func (*StdoutSender) Send

func (s *StdoutSender) Send(from string, to []string, msg io.WriterTo) error

Send will copy 'msg' to `os.Stdout`..

Jump to

Keyboard shortcuts

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