gomail

package module
v0.0.0-...-8217281 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2019 License: MIT Imports: 9 Imported by: 0

README

golang + Mail = GoMail (Gomail)

goMail (Golang for SMTP) is a Golang implementation for Simple Mail Transfer Protocol service. You can see an extended doc in godocs.

SMTP

SMTP is a protocol that you can send secure text messages trough the internet.
See more info here.

goMail

  • First, You should download my library:

    go get github.com/fmorenovr/gomail/
    
  • Then, you should use for differents implements in Go.

    • First, Create a gomail object:

        gomailObject := gomail.NewGomail()
      
        // credentials
        gomailObject.Set("Username", "aduncus@gomail.com")
        gomailObject.Set("Password", "********")
      
        // servername
        gomailObject.Set("Servername", "smtp.gmail.com:465")
      
        // from
        gomailObject.Set("From", "example@gomail.com")
        gomailObject.Set("From_name", "gomail Service")
      
        // to
        gomailObject.Set("To", "person1@gomail.com")
        gomailObject.Set("To_name", "Person 1")
      
        // subject
        gomailObject.Set("Subject", "This is the email subject")
      
        // body message
        gomailObject.Set("BodyMessage", "This is the fabulous body message\n\nGood Luck!!")
      
  • Finally, send a message:

     err := gomailObject.SendMessage()
     fmt.Println("Error: ", err)
    

Documentation

Overview

GoMail package is a SMTP library implemented in golang.

read more in Readme.md file

Example (SendingMessage)
package main

import (
	"fmt"
	"github.com/jenazads/gomail"
)

func main() {
	gomailObject, _ := gomail.NewGoMail()

	// credentials
	gomailObject.Set("Username", "aduncus@gomail.com")
	gomailObject.Set("Password", "********")

	// servername
	gomailObject.Set("Servername", "smtp.gmail.com:465")

	// from
	gomailObject.Set("From", "example@gomail.com")
	gomailObject.Set("From_name", "GoMail Service")

	// to
	gomailObject.Set("To", "person1@gomail.com")
	gomailObject.Set("To_name", "Person 1")

	// subject
	gomailObject.Set("Subject", "This is the email subject")

	// body message
	gomailObject.Set("BodyMessage", "This is the fabulous body message\n\nGood Luck!!")

	// set a list of recipients
	gomailObject.SetListToIds([]gomail.Recipients{{"Person in list 1", "personlist_1@gomail.com"}, {"Person in list 2", "personlist_2@gomail.com"}})

	// add another recipient
	gomailObject.AddToIds("Person added", "personadded@gomail.com")

	// repeat email with differents names
	gomailObject.AddToIds("Person added copy", "personadded@gomail.com")
	gomailObject.AddToIds("Person added no, im the copy", "personadded@gomail.com")
	gomailObject.AddToIds("Person added no, im the one", "personadded@gomail.com")

	// add other recipients
	gomailObject.AddListToIds([]gomail.Recipients{{"Person added in list 1", "personaddedlist_1@gomail.com"}, {"Person added in list 2", "personaddedlist_2@gomail.com"}})

	// delete any recipient
	gomailObject.DeleteToId("Email", "personlist_1@gomail.com")
	gomailObject.DeleteToId("Name", "Person to delete")

	// change info of any recipient
	gomailObject.ChangeToId("Email", "personadded@gomail.com", "personchangedMail@gomail.com")
	gomailObject.ChangeToId("Name", "Person added in list 1", "Person added in the list 1")

	err := gomailObject.SendMessage()
	fmt.Println("Error: ", err)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	GoMailErrBadFormatEmailFrom = errors.New("Bad format of email sender.\n")
	GoMailErrBadFormatEmailToId = errors.New("Bad format of email reciever.\n")
	GoMailErrMisbehavingServer  = errors.New("Server misbehaving.\n")
	GoMailErrWrongHostName      = errors.New("Wrong Host name.\n")
	GoMailErrSendMessage        = errors.New("Error sending message.\n")
	GoMailErrWriteClientClose   = errors.New("Closing Writer Client.\n")
	GoMailErrSMTPClient         = errors.New("Error Creating SMTP Client.\n")
	GoMailErrBadCredentials     = errors.New("Username and Password not accepted.\nCould be an error in credentials.\n")
	GoMailErrBadHostPortServer  = errors.New("Host or Port are incorrect and cannot connected with server. Or Server misbehaving.\n")
	GoMailErrSyntaxSender       = errors.New("Syntax error in sender.\n")
	GoMailErrSyntaxRecipients   = errors.New("Syntax error in recipients.\n.")
	GoMailErrMessageData        = errors.New("Error in data to send as message.\n")
	GoMailErrNotFoundTemplate   = errors.New("Not Found Template's Path to Response.\n")
	GoMailErrConvertToByte      = errors.New("Cannot Convert Template to bytes.\n")
)

list of errors

Functions

func NewGoMailAuth

func NewGoMailAuth(a *UserCredentials, host string) unEncryptedAuth

Instance an auth with a specific host

func VerifyFormatEmail

func VerifyFormatEmail(email string) bool

verify format of email

Types

type GoMail

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

GoMail object

func NewGoMail

func NewGoMail() (*GoMail, error)

Create a New Gomail instance

func (*GoMail) AddListToIds

func (o *GoMail) AddListToIds(toIdString []Recipients)

add list of ids of recipients

func (*GoMail) AddToIds

func (o *GoMail) AddToIds(name, email string)

add new recipient

func (*GoMail) ChangeToId

func (o *GoMail) ChangeToId(by, original, v string)

menu to change

func (*GoMail) DeleteToId

func (o *GoMail) DeleteToId(by, original string)

menu to delete

func (*GoMail) FindByEmail

func (o *GoMail) FindByEmail(email string) (aux int)

find by name

func (*GoMail) FindByName

func (o *GoMail) FindByName(name string) (aux int)

find by email

func (*GoMail) GetBodyMessage

func (o *GoMail) GetBodyMessage() string

get body message

func (*GoMail) GetContentType

func (o *GoMail) GetContentType() string

get content type

func (*GoMail) GetFrom

func (o *GoMail) GetFrom() string

get from

func (*GoMail) GetFromAddress

func (o *GoMail) GetFromAddress() string

get from address

func (*GoMail) GetFromName

func (o *GoMail) GetFromName() string

get from name

func (*GoMail) GetPassword

func (o *GoMail) GetPassword() string

get passwd

func (*GoMail) GetServerName

func (o *GoMail) GetServerName() string

get servername

func (*GoMail) GetSubject

func (o *GoMail) GetSubject() string

get subject message

func (*GoMail) GetToIdAddress

func (o *GoMail) GetToIdAddress(toId mail.Address) string

get specific recipient address

func (*GoMail) GetToIdName

func (o *GoMail) GetToIdName(toId mail.Address) string

get specific recipient name

func (*GoMail) GetToIds

func (o *GoMail) GetToIds() []mail.Address

get ids of recipients

func (*GoMail) GetToIdsToString

func (o *GoMail) GetToIdsToString() []string

get ids of recipients

func (*GoMail) GetUsername

func (o *GoMail) GetUsername() string

get username

func (*GoMail) PrepareMessage

func (o *GoMail) PrepareMessage() string

build the message

func (*GoMail) SendMessage

func (o *GoMail) SendMessage() error

Send Message

func (*GoMail) Set

func (o *GoMail) Set(key, value string)

menu to ser

func (*GoMail) SetBodyMessage

func (o *GoMail) SetBodyMessage(v string)

set body message

func (*GoMail) SetBodyMessageAsTemplate

func (o *GoMail) SetBodyMessageAsTemplate(templateToResPath string, infoMail interface{})

set boddy Message as Template

func (*GoMail) SetContentType

func (o *GoMail) SetContentType(v string)

set content type

func (*GoMail) SetFrom

func (o *GoMail) SetFrom(name, email string)

set from

func (*GoMail) SetFromAddress

func (o *GoMail) SetFromAddress(v string)

set from address

func (*GoMail) SetFromName

func (o *GoMail) SetFromName(v string)

set from name

func (*GoMail) SetListToIds

func (o *GoMail) SetListToIds(toIdString []Recipients)

set list of ids of recipients

func (*GoMail) SetPassword

func (o *GoMail) SetPassword(v string)

set passwd

func (*GoMail) SetServerName

func (o *GoMail) SetServerName(v string)

set servername

func (*GoMail) SetSubject

func (o *GoMail) SetSubject(v string)

set subject message

func (*GoMail) SetToIds

func (o *GoMail) SetToIds(name, email string)

set ids of recipients

func (*GoMail) SetToIdsAddress

func (o *GoMail) SetToIdsAddress(v string)

set unique recipient mail

func (*GoMail) SetToIdsName

func (o *GoMail) SetToIdsName(v string)

set unique recipient name

func (*GoMail) SetUsername

func (o *GoMail) SetUsername(v string)

set username

func (*GoMail) VerifyDuplicityByEmail

func (o *GoMail) VerifyDuplicityByEmail()

remove element if is duplicate (email or name).

func (*GoMail) VerifyDuplicityByName

func (o *GoMail) VerifyDuplicityByName()

remove element if is duplicate (email or name).

func (*GoMail) VerifyEmails

func (o *GoMail) VerifyEmails() error

verify all mails

type Recipients

type Recipients struct {
	Name  string
	Email string
}

Names and Mails from recipients

type SMTPServer

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

SMTP struct with host & port

func NewSMTPServer

func NewSMTPServer() *SMTPServer

new instance by defulat of SMTP server

func NewSMTPServerOptions

func NewSMTPServerOptions(mhost, mport string) *SMTPServer

new instance by defulat of SMTP server

func (*SMTPServer) GetServerHost

func (s *SMTPServer) GetServerHost() string

get server host

func (*SMTPServer) GetServerName

func (s *SMTPServer) GetServerName() string

get servername

func (*SMTPServer) GetServerPort

func (s *SMTPServer) GetServerPort() string

get server port

func (*SMTPServer) NewSMTPServerName

func (s *SMTPServer) NewSMTPServerName(v string)

new instance servername

func (*SMTPServer) SMTPServerTLS

func (s *SMTPServer) SMTPServerTLS() *tls.Config

set tls config to smtp server

func (*SMTPServer) SetServerHost

func (s *SMTPServer) SetServerHost(v string)

set server host

func (*SMTPServer) SetServerPort

func (s *SMTPServer) SetServerPort(v string)

set server port

type UserCredentials

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

username & passwd

func NewUserCredentials

func NewUserCredentials(u, v string) *UserCredentials

set username & passwd

func (*UserCredentials) GetPasswd

func (o *UserCredentials) GetPasswd() string

get passwd

func (*UserCredentials) GetUsername

func (o *UserCredentials) GetUsername() string

get username

func (*UserCredentials) SetPasswd

func (o *UserCredentials) SetPasswd(v string)

set passwd

func (*UserCredentials) SetUsername

func (o *UserCredentials) SetUsername(v string)

set username

Jump to

Keyboard shortcuts

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