func TestSendViaSMTP(t *testing.T) {
	t.Parallel()
	mail := new(MailService)
	mail.AutoText = true
	mail.FromDomain = "example.com"
	mail.FromName = "No Reply"
	mail.FromUsername = "no-reply"
	mail.Important = true
	mail.TrackClicks = true
	mail.TrackOpens = true
	client := newMockSMTPClient()
	email := mail.NewEmail()
	email.HTMLContent = "<html>Test</html>"
	email.PlainTextContent = "Test"
	f, err := os.Open("examples/test-attachment-file.txt")
	if err != nil {
		t.Fatalf("failed to attach file: %s", err.Error())
	} else {
		email.AddAttachment("test-attachment-file.txt", "text/plain", f)
	}
	var tests = []struct {
		input         string
		expectedError bool
	}{
		{"test@domain.com", false},
		{"test@badusername.com", true},
		{"test@badhostname.com", true},
	}
	for _, test := range tests {
		email.Recipients = []string{test.input}
		email.RecipientsCc = []string{test.input}
		email.RecipientsBcc = []string{test.input}
		email.ReplyToAddress = test.input
		if err = sendViaSMTP(client, email); err != nil && !test.expectedError {
			t.Fatalf("%s Failed: expected to NOT throw an error, inputted and [%s], error [%s]", t.Name(), test.input, err.Error())
		} else if err == nil && test.expectedError {
			t.Fatalf("%s Failed: expected to throw an error, inputted and [%s]", t.Name(), test.input)
		}
	}
}
TestSendViaSMTP will test the sendViaSMTP() method
package gomail
import (
	"bytes"
	"fmt"
	"io"
	"net/smtp"
	"os"
	"regexp"
	"testing"
	"github.com/domodwyer/mailyak"
)
type mockSMTPInterface struct {
	html      mailyak.BodyPart
	plain     mailyak.BodyPart
	toAddrs   []string
	trimRegex *regexp.Regexp
}
func (m *mockSMTPInterface) Send() error {
	if len(m.toAddrs) > 0 {
		if m.toAddrs[0] == "test@domain.com" {
			return nil
		}
		if m.toAddrs[0] == "test@badusername.com" {
			return fmt.Errorf("535 5.7.8")
		}
		if m.toAddrs[0] == "test@badhostname.com" {
			return fmt.Errorf("dial tcp: lookup smtp.badhostname.com: no such host")
		}
	}
	return nil
}
func (m *mockSMTPInterface) MimeBuf() (*bytes.Buffer, error) {
	return nil, nil
}
func (m *mockSMTPInterface) String() string {
	return ""
}
func (m *mockSMTPInterface) HTML() *mailyak.BodyPart {
	return &m.html
}
func (m *mockSMTPInterface) Plain() *mailyak.BodyPart {
	return &m.plain
}
func (m *mockSMTPInterface) To(addrs ...string) {
	m.toAddrs = []string{}
	for _, addr := range addrs {
		trimmed := m.trimRegex.ReplaceAllString(addr, "")
		if trimmed == "" {
			continue
		}
		m.toAddrs = append(m.toAddrs, trimmed)
	}
}
func (m *mockSMTPInterface) Bcc(addrs ...string) {}
func (m *mockSMTPInterface) WriteBccHeader(shouldWrite bool) {}
func (m *mockSMTPInterface) Cc(addrs ...string) {}
func (m *mockSMTPInterface) From(addr string) {}
func (m *mockSMTPInterface) FromName(name string) {}
func (m *mockSMTPInterface) ReplyTo(addr string) {}
func (m *mockSMTPInterface) Subject(sub string) {}
func (m *mockSMTPInterface) AddHeader(name, value string) {}
func (m *mockSMTPInterface) Attach(name string, r io.Reader) {}
func (m *mockSMTPInterface) AttachWithMimeType(name string, r io.Reader, mimeType string) {}
func (m *mockSMTPInterface) AttachInline(name string, r io.Reader) {}
func (m *mockSMTPInterface) AttachInlineWithMimeType(name string, r io.Reader, mimeType string) {}
func (m *mockSMTPInterface) ClearAttachments() {}
func TestNewSMTPClient(t *testing.T) {
	auth := smtp.PlainAuth("", "user", "password", "host")
	client := newSMTPClient("", auth)
	err := client.Send()
	if err == nil {
		t.Fatalf("error should have occurred, host was empty")
	}
	client = newSMTPClient("example.com", auth)
	err = client.Send()
	if err == nil {
		t.Fatalf("error should have occurred, host example.com")
	}
}
func newMockSMTPClient() smtpInterface {
	return &mockSMTPInterface{
		trimRegex: regexp.MustCompile("\r?\n"),
	}
}