smtpemail

package
v0.0.0-...-6fab949 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2023 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BothNotFound = -2
)
View Source
const Scheme = "smtp"

Scheme is the URL scheme smtpmailprovider registers its URLOpener under on mailprovider.DefaultMux.

Variables

This section is empty.

Functions

func AddTemplate

func AddTemplate(t *emailtemplate.Template) error

AddTemplate adds a template to the default templates.

func AddTemplateVersion

func AddTemplateVersion(tempName string, t *emailtemplate.TemplateVersion) error

AddTemplateVersion adds a template version to the default templates.

func LoginAuth

func LoginAuth(username, password, host string) smtp.Auth

LoginAuth returns an Auth that implements the LOGIN authentication

func OpenSender

func OpenSender(ctx context.Context, d *Dialer, opts SenderOptions, deliveryTopic *pubsub.Topic) (*email.Sender, error)

OpenSender opens the Sender based on the provided Dialer. The deliveryTopic is optional and can be used to publish delivery events to the provided topic. If the deliveryTopic is nil, no delivery events will be published.

func OpenTemplatedSender

func OpenTemplatedSender(ctx context.Context, d *Dialer, opts SenderOptions, t *emailtemplate.ParsedTemplates, delivery *pubsub.Topic) (*email.TemplatedSender, error)

OpenTemplatedSender opens the TemplatedSender based on the provided Dialer.

func UpsertTemplateVersion

func UpsertTemplateVersion(tempName string, t *emailtemplate.TemplateVersion) error

UpsertTemplateVersion adds or updates a template version to the default templates.

Types

type Dialer

type Dialer struct {
	// Host is the hostname or IP address of the smtp server.
	Host string
	// Port is the Port of the smtp server.
	Port uint16
	// Username is the Username used to authenticate to the smtp server.
	Username string
	// Password is the Password used to authenticate to the smtp server.
	Password string
	// LocalName is the hostname of the sender machine, which is used for the HELO/EHLO.
	// By default, "localhost" is sent.
	// Some SMTP servers requires LocalName to match the ip address of the sender machine.
	LocalName string
	// Auth is the authentication mechanism used when the smtp server does not
	Auth smtp.Auth
	// SSL defines whether an SSL connection is used. It should be false in
	// most cases since the authentication mechanism should use the STARTTLS
	// extension instead.
	SSL bool
	// TSLConfig represents the TLS configuration used for the TLS (when the
	// STARTTLS extension is used) or SSL connection.
	TLSConfig *tls.Config
}

Dialer is used to dial the smtp server.

func ParseDialerURL

func ParseDialerURL(smtpURL string) (*Dialer, error)

ParseDialerURL parses Dialer from the input URL. The URL is expected to be in the following format:

smtp[s]://[username[:password]@]host[:port][?localname=localname&ssl=ssl&auth=auth]

The username and password are used to authenticate to the smtp server. The following query parameters are supported:

  • localname: the domain of the sender, which is used for the HELO/EHLO, if not defined, the Domain field is used. by default, "localhost" is sent.
  • ssl: defines whether an SSL connection is used. It should be false in most cases since the authentication mechanism should use the STARTTLS extension instead.
  • auth: the authentication mechanism used when the smtp server does not support the STARTTLS extension. The following values are supported: "plain", "login", "md5". By default client tries to check if server supports CRAM-MD5, LOGIN, PLAIN authentication in this order.

func (*Dialer) Validate

func (d *Dialer) Validate() error

Validate validates the Dialer configuration.

type Encoding

type Encoding string

Encoding represents a MIME encoding scheme like quoted-printable or base64.

const (
	// QuotedPrintable represents the quoted-printable encoding as defined in
	// RFC 2045.
	QuotedPrintable Encoding = "quoted-printable"
	// Base64 represents the base64 encoding as defined in RFC 2045.
	Base64 Encoding = "base64"
	// Unencoded can be used to avoid encoding the body of an email. The headers
	// will still be encoded using quoted-printable encoding.
	Unencoded Encoding = "8bit"
)

func (*Encoding) FromString

func (e *Encoding) FromString(in string) error

FromString parses an Encoding from a string.

type SenderOptions

type SenderOptions struct {
	// Encoding determines the Content-Transfer-Encoding of the message body.
	// By default, "quoted-printable" is used.
	Encoding Encoding
	// MaxBatchSize is the maximum number of messages sent in a single batch.
	// By default, 1 is used.
	MaxBatchSize int
	// MaxHandlers is the maximum number of parallel handlers used to send
	// messages. By default, 1 is used.
	MaxHandlers int
	// Charset is the charset of the message body.
	// By default, "utf-8" is used.
	Charset string
}

SenderOptions contains options for the Sender.

type URLOpener

type URLOpener struct {
	// Dialer is the dialer used to connect to the SMTP server.
	Dialer *Dialer
	// SenderOptions contains options for the Sender.
	SenderOptions SenderOptions
	// Templates is a set of parsed templates used to render the templated messages.
	Templates *emailtemplate.ParsedTemplates
	// TopicOpener is used to open the topic for the delivery event.
	// If nil, the default pubsub.URLMux is used.
	TopicOpener *pubsub.URLMux
}

URLOpener opens smtp URLs like "smtp://?encoding=quoted-printable&maxbatchsize=10&auth=md5"

The URL Host+Port are used as the SMTP server address. The following query parameters are supported:

  • charset: the charset of the message body. By default, "utf-8" is used.
  • encoding: the encoding of the message body. By default, "quoted-printable" is used. The following values are supported: "quoted-printable", "base64", "binary".
  • maxbatchsize: the maximum number of messages sent in a single batch. By default, 1 is used.
  • maxhandlers: the maximum number of parallel handlers used to send messages. By default, 1 is used.
  • deliverytopic: optional parameter to specify the topic to which the delivery event is published. If not specified, no delivery event is published. The topic query must follow the format described in the gocloud.dev/pubsub package documentation, and load suitable driver for it. The topic needs to be query parameter encoded.

func (*URLOpener) OpenSenderURL

func (o *URLOpener) OpenSenderURL(ctx context.Context, u *url.URL) (*email.Sender, error)

OpenSenderURL opens the mail provider at the URLs path.

func (*URLOpener) OpenTemplatedSenderURL

func (o *URLOpener) OpenTemplatedSenderURL(ctx context.Context, u *url.URL) (*email.TemplatedSender, error)

OpenTemplatedSenderURL opens the mail provider at the URLs path.

Jump to

Keyboard shortcuts

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