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 ¶
- Variables
- func NewGoMailAuth(a *UserCredentials, host string) unEncryptedAuth
- func VerifyFormatEmail(email string) bool
- type GoMail
- func (o *GoMail) AddListToIds(toIdString []Recipients)
- func (o *GoMail) AddToIds(name, email string)
- func (o *GoMail) ChangeToId(by, original, v string)
- func (o *GoMail) DeleteToId(by, original string)
- func (o *GoMail) FindByEmail(email string) (aux int)
- func (o *GoMail) FindByName(name string) (aux int)
- func (o *GoMail) GetBodyMessage() string
- func (o *GoMail) GetContentType() string
- func (o *GoMail) GetFrom() string
- func (o *GoMail) GetFromAddress() string
- func (o *GoMail) GetFromName() string
- func (o *GoMail) GetPassword() string
- func (o *GoMail) GetServerName() string
- func (o *GoMail) GetSubject() string
- func (o *GoMail) GetToIdAddress(toId mail.Address) string
- func (o *GoMail) GetToIdName(toId mail.Address) string
- func (o *GoMail) GetToIds() []mail.Address
- func (o *GoMail) GetToIdsToString() []string
- func (o *GoMail) GetUsername() string
- func (o *GoMail) PrepareMessage() string
- func (o *GoMail) SendMessage() error
- func (o *GoMail) Set(key, value string)
- func (o *GoMail) SetBodyMessage(v string)
- func (o *GoMail) SetBodyMessageAsTemplate(templateToResPath string, infoMail interface{})
- func (o *GoMail) SetContentType(v string)
- func (o *GoMail) SetFrom(name, email string)
- func (o *GoMail) SetFromAddress(v string)
- func (o *GoMail) SetFromName(v string)
- func (o *GoMail) SetListToIds(toIdString []Recipients)
- func (o *GoMail) SetPassword(v string)
- func (o *GoMail) SetServerName(v string)
- func (o *GoMail) SetSubject(v string)
- func (o *GoMail) SetToIds(name, email string)
- func (o *GoMail) SetToIdsAddress(v string)
- func (o *GoMail) SetToIdsName(v string)
- func (o *GoMail) SetUsername(v string)
- func (o *GoMail) VerifyDuplicityByEmail()
- func (o *GoMail) VerifyDuplicityByName()
- func (o *GoMail) VerifyEmails() error
- type Recipients
- type SMTPServer
- func (s *SMTPServer) GetServerHost() string
- func (s *SMTPServer) GetServerName() string
- func (s *SMTPServer) GetServerPort() string
- func (s *SMTPServer) NewSMTPServerName(v string)
- func (s *SMTPServer) SMTPServerTLS() *tls.Config
- func (s *SMTPServer) SetServerHost(v string)
- func (s *SMTPServer) SetServerPort(v string)
- type UserCredentials
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
Types ¶
type GoMail ¶
type GoMail struct {
// contains filtered or unexported fields
}
GoMail object
func (*GoMail) AddListToIds ¶
func (o *GoMail) AddListToIds(toIdString []Recipients)
add list of ids of recipients
func (*GoMail) GetToIdAddress ¶
get specific recipient address
func (*GoMail) GetToIdName ¶
get specific recipient name
func (*GoMail) GetToIdsToString ¶
get ids of recipients
func (*GoMail) SetBodyMessageAsTemplate ¶
set boddy Message as Template
func (*GoMail) SetListToIds ¶
func (o *GoMail) SetListToIds(toIdString []Recipients)
set list of ids of recipients
func (*GoMail) SetToIdsAddress ¶
set unique recipient mail
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).
type Recipients ¶
Names and Mails from recipients
type SMTPServer ¶
type SMTPServer struct {
// contains filtered or unexported fields
}
SMTP struct with host & port
func NewSMTPServerOptions ¶
func NewSMTPServerOptions(mhost, mport string) *SMTPServer
new instance by defulat of SMTP server
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
type UserCredentials ¶
type UserCredentials struct {
// contains filtered or unexported fields
}
username & passwd
func NewUserCredentials ¶
func NewUserCredentials(u, v string) *UserCredentials
set username & passwd
Click to show internal directories.
Click to hide internal directories.