email

package module
v0.0.0-...-1ac27de Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2019 License: MIT Imports: 5 Imported by: 0

README

Email

A simple package that makes sending emails in GO easy and straight forward.

go get github.com/jakobii/email

Example

package main

import (
	"github.com/jakobii/email"
)

func main() {

	// reusable authentication
	auth := email.Auth{
		Server:   "smtp.gmail.com",
		Port:     587,
		Username: "user@gmail.com",
		Password: "p@$$w0rd",
	}

	// a single email message
	msg := email.Message{
		From:    "user@gmail.com",
		To:      []string{"user2@gmail.com", "user3@gmail.com"},
		Subject: "test passed!",

		// note that the Body's ContentType defaults to email.HTML
		//BodyType: email.Plain or email.HTML
		Body:    []byte("<h1 style=\"color:green;\">This Test Passed!!!</h1>"),
	}

	// send email
	err := auth.Send(msg)
	if err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Send

func Send(Server string, Port int, Username string, Password string, From string, To []string, Cc []string, Bcc []string, Subject string, Body []byte, Content ContentType) error

Send is a simple function that will send emails the parameter list is large but its a one stop solution to sending an email.

Types

type Auth

type Auth struct {
	Server   string
	Port     int
	Username string
	Password string
}

Auth provide basic smtp parameter

func (*Auth) Send

func (a *Auth) Send(m Message) error

Send method is a more realistic approach to sending emails authentication is packages seperately in a struct to be reused.

type ContentType

type ContentType string

ContentType defines the type of body the email will have.

const (
	HTML  ContentType = "text/html"
	Plain ContentType = "text/plain"
)

maybe there are more email content types out there.. idk..

func (ContentType) String

func (t ContentType) String() string

type Message

type Message struct {
	From     string
	To       []string
	Cc       []string
	Bcc      []string
	Subject  string
	Body     []byte
	BodyType ContentType
}

Message represents a single email message

Jump to

Keyboard shortcuts

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