emaillib

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: MIT Imports: 4 Imported by: 0

README

emaillib

Package in Go for sending emails. Encapsulates jordan-wright/email. Probably not useful for anybody else than me.

Usage

emailer := email.NewClient()
_ := emailer.Sendmail("John Doe", "jd@example.com", "Subject", "Some message")

emailer := email.NewClient()
emailer.To("John Doe", "john@example.com")
emailer.Subject("Subject of message")
emailer.BodyText("A bit of a message")
_ := emailer.Send()

Configuration

Create a new email object with the NewClient function. It takes a variadic number of configuration functions as parameters

Configure SMTP host and port
emailer := email.NewClient(
  email.WithRelayhost("smtp.example.com", 465),
)
Configure authentication
emailer := email.NewClient(
  email.WithAuth("your.name@example.com", "123456789abcde", true),
)
Configure a default sender email address (and name)
emailer := email.NewClient(
  email.WithSender("Example Inc. Customer Service", "info@example.com"),
)
Configure development mode without real sending
emailer := email.NewClient(
  email.WithDontSend(),
)
Combine multiple configuration functions

All possible configuration functions can be combined:

emailer := email.NewClient(
  email.WithRelayhost("smtp.fastmail.com", 465),
  email.WithAuth("your.name@example.com", "123456789abcde"),
  email.WithSender("Example Inc. Customer Service", "info@example.com"),
  email.WithDontSend(),
)

Installation

You can install this package in your project by running:

go get -u github.com/jakoubek/emaillib

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a struct for holding the configuration of the email client and a pointer to the email object from the library.

func NewClient

func NewClient(opts ...ClientConfig) *Client

NewClient returns a Client object. The object was optionally configured with a variadic list of ClientConfig functions.

func (*Client) AttachFile

func (c *Client) AttachFile(filename string)

AttachFile attaches a file to the email Client.

func (*Client) BCC added in v0.4.0

func (c *Client) BCC(toName, toEmail string)

BCC adds an email address to the list of BCC addresses.

func (*Client) BodyHTML

func (c *Client) BodyHTML(bodyHTML string)

BodyHTML sets the HTML part of the body

func (*Client) BodyText

func (c *Client) BodyText(bodyText string)

BodyText sets the plaintext of the body

func (*Client) CC

func (c *Client) CC(toName, toEmail string)

CC adds an email address to the list of CC addresses.

func (*Client) Debug

func (c *Client) Debug() string

Debug returns a debug string with all settings in the Client.

func (*Client) From

func (c *Client) From(fromName, fromEmail string)

From sets the from address

func (*Client) NewMessage

func (c *Client) NewMessage()

func (*Client) Send

func (c *Client) Send() error

Send sends the prepared email message

func (*Client) Sendmail

func (c *Client) Sendmail(toName, toEmail, subject, message string) error

Sendmail sends an email with a given subject and body text to the provided email address. This is a shortcut to To, Subject, ....

func (*Client) Subject

func (c *Client) Subject(subject string)

Subject sets the email subject to the provided string.

func (*Client) To

func (c *Client) To(toName, toEmail string)

To adds an email address to the list of recipient addresses (TO).

type ClientConfig

type ClientConfig func(*Client)

ClientConfig is a type for the variadic functions to configure the Client object.

func WithAuth

func WithAuth(username, password string, useAuth bool) ClientConfig

WithAuth configures the Client with a username and password for authentication with the SMTP server; sets the corresponding flag useAuth as well.

func WithDontSend

func WithDontSend() ClientConfig

WithDontSend configures the Client with the dontSend flag, i.e. there is no email sent.

func WithRelayhost

func WithRelayhost(host string, port int) ClientConfig

WithRelayhost configures the Client with a host name and a port to send the email to.

func WithSender

func WithSender(name, email string) ClientConfig

WithSender configures the Client with a sender name and email address.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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