func TestEmail_ApplyTemplates(t *testing.T) {
	t.Parallel()
	mail := new(MailService)
	mail.AutoText = true
	mail.FromUsername = "no-reply"
	mail.FromName = "No Reply"
	mail.FromDomain = "example.com"
	mail.Important = true
	email := mail.NewEmail()
	parsedTemplate, err := email.ParseTemplate(filepath.Join("examples", "example_template.txt"))
	if err != nil {
		t.Fatalf("%s: error occurred: %s", t.Name(), err.Error())
	} else if parsedTemplate == nil {
		t.Fatalf("%s: template was nil", t.Name())
	} else if parsedTemplate.Name() != "example_template.txt" {
		t.Fatalf("%s: template name expected [%s] does not match [%s]", t.Name(), "example_template.txt", parsedTemplate.Name())
	}
	if email.CSS, err = ioutil.ReadFile(filepath.Join("examples", "example_theme.css")); err != nil {
		t.Fatalf("%s: error occurred: %s", t.Name(), err.Error())
	}
	var parsedHTMLTemplate *template.Template
	parsedHTMLTemplate, err = email.ParseHTMLTemplate(filepath.Join("examples", "example_template_css.html"))
	if err != nil {
		t.Fatalf("%s: error occurred: %s", t.Name(), err.Error())
	} else if parsedHTMLTemplate == nil {
		t.Fatalf("%s: template was nil", t.Name())
	} else if parsedHTMLTemplate.Name() != "example_template_css.html" {
		t.Fatalf("%s: template name expected [%s] does not match [%s]", t.Name(), "example_template_css.html", parsedHTMLTemplate.Name())
	}
	if err = email.ApplyTemplates(parsedHTMLTemplate, parsedTemplate, mail); err != nil {
		t.Fatalf("%s: error occurred: %s", t.Name(), err.Error())
	}
	if err = email.ApplyTemplates(parsedHTMLTemplate, parsedTemplate, nil); err != nil {
		t.Fatalf("%s: error occurred: %s", t.Name(), err.Error())
	}
	if err = email.ApplyTemplates(parsedHTMLTemplate, parsedTemplate, "no data"); err == nil {
		t.Fatalf("%s: error should have occurred", t.Name())
	}
}
TestEmail_ApplyTemplates tests the method ApplyTemplates()
package gomail
import (
	"fmt"
	"html/template"
	"io/ioutil"
	"path/filepath"
	"testing"
)
func TestMailService_NewEmail(t *testing.T) {
	t.Parallel()
	mail := new(MailService)
	mail.AutoText = true
	mail.FromUsername = "no-reply"
	mail.FromName = "No Reply"
	mail.FromDomain = "example.com"
	mail.Important = true
	email := mail.NewEmail()
	if email.FromAddress != mail.FromUsername+"@"+mail.FromDomain {
		t.Fatalf("%s: FromAddress is invalid", t.Name())
	}
	if email.ReplyToAddress != email.FromAddress {
		t.Fatalf("%s: ReplyToAddress is invalid", t.Name())
	}
	if !email.AutoText {
		t.Fatalf("%s: AutoText is invalid", t.Name())
	}
	if !email.Important {
		t.Fatalf("%s: Important is invalid", t.Name())
	}
	if email.FromName != mail.FromName {
		t.Fatalf("%s: FromName is invalid", t.Name())
	}
}
func ExampleMailService_NewEmail() {
	mail := new(MailService)
	mail.FromUsername = "no-reply"
	mail.FromName = "No Reply"
	mail.FromDomain = "example.com"
	email := mail.NewEmail()
	fmt.Printf("new email with from address: %s", email.FromAddress)
}
func BenchmarkMailService_NewEmail(b *testing.B) {
	mail := new(MailService)
	mail.FromUsername = "no-reply"
	mail.FromName = "No Reply"
	mail.FromDomain = "example.com"
	for i := 0; i < b.N; i++ {
		_ = mail.NewEmail()
	}
}
func TestEmail_AddAttachment(t *testing.T) {
	t.Parallel()
	mail := new(MailService)
	mail.FromUsername = "no-reply"
	mail.FromName = "No Reply"
	mail.FromDomain = "example.com"
	email := mail.NewEmail()
	email.AddAttachment("testName", "testType", nil)
	email.AddAttachment("testName2", "testType2", nil)
	if len(email.Attachments) != 2 {
		t.Fatalf("%s: expected 2 attachments, got: %d", t.Name(), len(email.Attachments))
	}
	if email.Attachments[0].FileName != "testName" || email.Attachments[0].FileType != "testType" {
		t.Fatalf("%s: expected value was wrong, got: %s", t.Name(), email.Attachments[0].FileName)
	}
	if email.Attachments[1].FileName != "testName2" || email.Attachments[1].FileType != "testType2" {
		t.Fatalf("%s: expected value was wrong, got: %s", t.Name(), email.Attachments[0].FileName)
	}
}
func ExampleEmail_AddAttachment() {
	mail := new(MailService)
	mail.FromUsername = "no-reply"
	mail.FromName = "No Reply"
	mail.FromDomain = "example.com"
	email := mail.NewEmail()
	email.AddAttachment("testName", "testType", nil)
	fmt.Printf("attachment: %s", email.Attachments[0].FileName)
}
func BenchmarkEmail_AddAttachment(b *testing.B) {
	mail := new(MailService)
	mail.FromUsername = "no-reply"
	mail.FromName = "No Reply"
	mail.FromDomain = "example.com"
	email := mail.NewEmail()
	for i := 0; i < b.N; i++ {
		email.AddAttachment("testName", "testType", nil)
	}
}
func TestEmail_ParseTemplate(t *testing.T) {
	t.Parallel()
	mail := new(MailService)
	mail.AutoText = true
	mail.FromUsername = "no-reply"
	mail.FromName = "No Reply"
	mail.FromDomain = "example.com"
	mail.Important = true
	email := mail.NewEmail()
	parsedTemplate, err := email.ParseTemplate(filepath.Join("examples", "example_template.txt"))
	if err != nil {
		t.Fatalf("%s: error occurred: %s", t.Name(), err.Error())
	} else if parsedTemplate == nil {
		t.Fatalf("%s: template was nil", t.Name())
	} else if parsedTemplate.Name() != "example_template.txt" {
		t.Fatalf("%s: template name expected [%s] does not match [%s]", t.Name(), "example_template.txt", parsedTemplate.Name())
	}
	_, err = email.ParseTemplate(filepath.Join("examples", "missing_file.txt"))
	if err == nil {
		t.Fatalf("%s: error expected but was nil", t.Name())
	}
}
func TestEmail_ParseHTMLTemplate(t *testing.T) {
	t.Parallel()
	mail := new(MailService)
	mail.AutoText = true
	mail.FromUsername = "no-reply"
	mail.FromName = "No Reply"
	mail.FromDomain = "example.com"
	mail.Important = true
	email := mail.NewEmail()
	parsedTemplate, err := email.ParseHTMLTemplate(filepath.Join("examples", "example_template.html"))
	if err != nil {
		t.Fatalf("%s: error occurred: %s", t.Name(), err.Error())
	} else if parsedTemplate == nil {
		t.Fatalf("%s: template was nil", t.Name())
	} else if parsedTemplate.Name() != "example_template.html" {
		t.Fatalf("%s: template name expected [%s] does not match [%s]", t.Name(), "example_template.html", parsedTemplate.Name())
	}
	parsedTemplate, err = email.ParseHTMLTemplate(filepath.Join("examples", "example_template_css.html"))
	if err != nil {
		t.Fatalf("%s: error occurred: %s", t.Name(), err.Error())
	} else if parsedTemplate == nil {
		t.Fatalf("%s: template was nil", t.Name())
	} else if parsedTemplate.Name() != "example_template_css.html" {
		t.Fatalf("%s: template name expected [%s] does not match [%s]", t.Name(), "example_template_css.html", parsedTemplate.Name())
	}
	_, err = email.ParseHTMLTemplate(filepath.Join("examples", "missing_file.html"))
	if err == nil {
		t.Fatalf("%s: error expected but was nil", t.Name())
	}
}