mailer

package
v0.0.0-...-ac2e00c Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package mailer provides functions to easily send emails.

This package should be used with or inside a package that helps writing emails like it is done in the package github.com/alexcesaro/mail/gomail

package main

import (
	"log"
	"net/mail"
	"strings"

	"github.com/alexcesaro/mail/mailer"
)

func main() {
	msg := &mail.Message{
		mail.Header{
			"From":         {"alex@example.com"},
			"To":           {"bob@example.com", "cora@example.com"},
			"Subject":      {"Hello!"},
			"Content-Type": {"text/plain"},
		},
		strings.NewReader("Hello, how are you ?"),
	}

	m := mailer.NewMailer("smtp.example.com", "user", "123456", 25)
	if err := m.Send(msg); err != nil { // This will send the email to Bob and Cora
		log.Println(err)
	}
}

Index

Constants

This section is empty.

Variables

View Source
var SendMail = smtp.SendMail

Stubbed out for testing.

Functions

This section is empty.

Types

type Mailer

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

A Mailer represents an SMTP server.

func NewCustomMailer

func NewCustomMailer(auth smtp.Auth, addr string) *Mailer

NewCustomMailer creates a mailer using any authentication mechanism.

func NewMailer

func NewMailer(host string, username string, password string, port int) *Mailer

NewMailer returns a mailer. The given parameters are used to connect to the SMTP server via a PLAIN authentication mechanism.

func (*Mailer) Send

func (m *Mailer) Send(msg *mail.Message) error

Send sends the emails to the recipients of the message.

Jump to

Keyboard shortcuts

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