email

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2020 License: MIT Imports: 10 Imported by: 0

README

FetchWeb Mail

Go Report Card Go Doc GitHub release

Introduction

FetchWeb Email is a simple SMTP Email API written in Go with no dependencies outside of the Go standard library.

Setup Example

package main

import (
	"encoding/json"
	"io/ioutil"

	email "github.com/FetchWeb/Email"
)

func main() {
	// Initailise credentials & data objects.
	creds := &email.Credentials{
		Address: "<Sending email address>",
		Hostname: "<Hostname of SMTP Server>",
		Name: "<Name appearing on email>",
		Port: "<Port email being sent on>",
		Password "<Password to email account>"
	}
	data := &email.Data{
		Attachments: make(map[string]*email.Attachment)
	}

	// Add email body.
	data.Body = "Hello world from FetchWeb Mail!"

	// Add attachment from file.
	if err := data.AddAttachmentFromFile("<Attachment directory>", false); err != nil {
		panic(err)
	}

	// Send email.
	if err := email.Send(creds, data); err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

View Source
const (
	MessageTypePlain = "text/plain"
	MessageTypeHTML  = "text/html"
)

Message type constants.

Variables

This section is empty.

Functions

func Send added in v0.2.0

func Send(credentials *Credentials, data *Data) error

Send sends the email.

Types

type Attachment added in v0.2.0

type Attachment struct {
	Filename string `json:"filename"`
	Data     string `json:"data"`
	Inline   bool   `json:"inline"`
}

Attachment represents an email attachment.

type Credentials added in v0.2.0

type Credentials struct {
	Address  string `json:"address"`
	Hostname string `json:"hostname"`
	Name     string `json:"name"`
	Password string `json:"password"`
	Port     string `json:"port"`
}

Credentials stores the relevant credenial data to send emails.

type Data added in v0.2.0

type Data struct {
	From            mail.Address  `json:"from"`
	To              []string      `json:"to"`
	CC              []string      `json:"cc"`
	BCC             []string      `json:"bcc"`
	ReplyTo         string        `json:"reply_to"`
	Subject         string        `json:"subject"`
	Body            string        `json:"body"`
	BodyContentType string        `json:"body_content_type"`
	Headers         []*Header     `json:"headers"`
	Attachments     []*Attachment `json:"attachments"`
}

Data represents a smtp email.

func (*Data) AddAttachmentFromBuffer added in v0.2.0

func (d *Data) AddAttachmentFromBuffer(filename string, buffer []byte, inline bool)

AddAttachmentFromBuffer adds an attachment already in a byte array to the Data.

func (*Data) AddAttachmentFromFile added in v0.2.0

func (d *Data) AddAttachmentFromFile(file string, inline bool) error

AddAttachmentFromFile adds an attachment from a directory to the Data.

func (*Data) AddHeader added in v0.2.0

func (d *Data) AddHeader(key string, value string) *Header

AddHeader ads a Header to the Data.

func (*Data) GetRecipients added in v0.2.0

func (d *Data) GetRecipients() []string

GetRecipients returns all the recipients from the Data.

func (*Data) ToByteArray added in v0.2.0

func (d *Data) ToByteArray() []byte

ToByteArray returns all the Data as a byte array.

type Header struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

Header represents an additional email header.

Jump to

Keyboard shortcuts

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