email

package module
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2019 License: MIT Imports: 16 Imported by: 1

README

Build Status Coverage Status

email

Library to send email messages, written in go. This library is using the standard library to make up all the moving parts in sending email messages. No external dependencies required.

Use

To use the library you need to construct three parts:

  • SMTPServer The smtp server the message is being submitted to
  • User The authorized email user sending the message
  • Message The message that is to be constructed and sent
package main

import (
	"log"
	"net/mail"

	"github.com/ppreeper/email"
)

func main() {

	d := email.Attachment{
		Filename: "test.txt",
		Data:     []byte("oh yeah"),
		Inline:   false,
	}

	//create message
	m := email.Message{
		From:     mail.Address{"Mailer", "mailer@example.com"},
		To:       []mail.Address{{"Standard User", "standard.user@example.com"}},
		Subject:  "test subject",
		Body:     "this is the email body",
		MimeType: "text/html",
	}
	m.Attachments = make(map[string]*email.Attachment)
	m.Attachments["test.txt"] = &d
  
	// Connect to the remote SMTP server.
	user := email.User{Username: "mailer@example.com", Password: "pa55w0rd"}
	server := email.SMTPServer{Host: "mail.example.com", Port: "25", STARTTLS: false}

	err := server.Send(&user, &m)
	if err != nil {
		log.Fatal(err)
	}
}

Status

This library is a work in progress but has been tested against a MS Exchange server and a Postfix server configured with starttls.

Issues

  • bcc not functioning as expected
  • testing on exchange did not send messages outside of organization, but postfix worked sending to internal/external recipients

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	Filename string
	Data     []byte
	Inline   bool
}

Attachment for email attachment

type Message

type Message struct {
	From        mail.Address
	To          []mail.Address
	Cc          []mail.Address
	Bcc         []mail.Address
	ReplyTo     mail.Address
	Subject     string
	Body        string
	MimeType    string
	Attachments map[string]*Attachment
}

Message SMTP Message

func (*Message) Attach

func (m *Message) Attach(file string, inline bool) error

Attach file to SMTP Message

func (*Message) BuildMessage

func (m *Message) BuildMessage() []byte

BuildMessage returns byte ready email file

type SMTPServer

type SMTPServer struct {
	Host     string
	Port     string
	STARTTLS bool
}

SMTPServer host setup

func (*SMTPServer) Send

func (s *SMTPServer) Send(u *User, m *Message) error

Send smtp message

func (*SMTPServer) SendMail added in v0.0.6

func (s *SMTPServer) SendMail(user User, from string, to []string, msg []byte) error

SendMail requires no tls

func (*SMTPServer) ServerName

func (s *SMTPServer) ServerName() string

ServerName return host port combo

type User

type User struct {
	Username string
	Password string
	Auth     bool
}

User client

Jump to

Keyboard shortcuts

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