|
@@ -4,6 +4,7 @@ package email
|
|
|
|
|
|
import (
|
|
import (
|
|
"bytes"
|
|
"bytes"
|
|
|
|
+ "errors"
|
|
"fmt"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
"log"
|
|
"log"
|
|
@@ -75,13 +76,16 @@ func (e *Email) Bytes() []byte {
|
|
e.Headers.Set("From", e.From)
|
|
e.Headers.Set("From", e.From)
|
|
e.Headers.Set("Subject", e.Subject)
|
|
e.Headers.Set("Subject", e.Subject)
|
|
//Write the envelope headers (including any custom headers)
|
|
//Write the envelope headers (including any custom headers)
|
|
-
|
|
|
|
return buff.Bytes()
|
|
return buff.Bytes()
|
|
}
|
|
}
|
|
|
|
|
|
//Send an email using the given host and SMTP auth (optional), returns any error thrown by smtp.SendMail
|
|
//Send an email using the given host and SMTP auth (optional), returns any error thrown by smtp.SendMail
|
|
//This function merges the To, Cc, and Bcc fields and calls the smtp.SendMail function using the Email.Bytes() output as the message
|
|
//This function merges the To, Cc, and Bcc fields and calls the smtp.SendMail function using the Email.Bytes() output as the message
|
|
func (e *Email) Send(addr string, a smtp.Auth) error {
|
|
func (e *Email) Send(addr string, a smtp.Auth) error {
|
|
|
|
+ //Check to make sure there is at least one recipient and one "From" address
|
|
|
|
+ if e.From == "" || len(e.To) == 0 {
|
|
|
|
+ return errors.New("Must specify at least one From address and one To address")
|
|
|
|
+ }
|
|
// Merge the To, Cc, and Bcc fields
|
|
// Merge the To, Cc, and Bcc fields
|
|
to := append(append(e.To, e.Cc...), e.Bcc...)
|
|
to := append(append(e.To, e.Cc...), e.Bcc...)
|
|
from, err := mail.ParseAddress(e.From)
|
|
from, err := mail.ParseAddress(e.From)
|