Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhaqim committed Apr 19, 2024
1 parent a2c0628 commit ba13783
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 8 deletions.
2 changes: 1 addition & 1 deletion error.go → errors/error.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gomail
package errors

import "errors"

Expand Down
10 changes: 10 additions & 0 deletions example/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module gomailtesting

go 1.22.1

require (
github.com/Rhaqim/gomail v1.0.0-beta
)

// add module from src folder
replace github.com/Rhaqim/gomail => ../
37 changes: 37 additions & 0 deletions example/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"log"

"github.com/Rhaqim/gomail"
)

func main() {
auth := gomail.EmailAuthConfig{
Host: "smtp.gmail.com",
Port: 587,
Username: "user",
Password: "password",
From: "[email protected]",
}

var g gomail.Gomail = gomail.NewGomail(auth, "example/templates")

App(g)

}

func App(mail gomail.Gomail) {

email := &gomail.Email{
Recipients: []string{"[email protected]", "[email protected]"},
Subject: "Hello",
Body: "Hello, this is a test email",
TemplateFileName: "hello.html",
}

err := mail.SendEmail(email)
if err != nil {
log.Fatal(err)
}
}
10 changes: 10 additions & 0 deletions example/templates/hello.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>My Go Template</title>
</head>
<body>
<h1>{{.Title }}</h1>
<p>{{ .Body }}</p>
</body>
</html>
16 changes: 9 additions & 7 deletions gomail.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"net/smtp"
"sync"
"text/template"

"github.com/Rhaqim/gomail/errors"
)

// Goemail is an interface for sending emails and parsing templates.
Expand Down Expand Up @@ -39,31 +41,31 @@ func (g *GoemailConfig) validate(kind ValidateKind) error {
switch kind {
case auth:
if g.Config.Host == "" {
return ErrEmptyHost
return errors.ErrEmptyHost
}

if g.Config.Port == 0 {
return ErrEmptyPort
return errors.ErrEmptyPort
}

if g.Config.Username == "" {
return ErrEmptyUsername
return errors.ErrEmptyUsername
}

if g.Config.Password == "" {
return ErrEmptyPassword
return errors.ErrEmptyPassword
}

if g.Config.From == "" {
return ErrEmptyFrom
return errors.ErrEmptyFrom
}

if g.TemplateDir == "" {
return ErrEmptyTemplateDir
return errors.ErrEmptyTemplateDir
}
case email:
if len(g.email.Recipients) == 0 {
return ErrEmptyTo
return errors.ErrEmptyTo
}
}

Expand Down

0 comments on commit ba13783

Please sign in to comment.