github.com/bitcubate/cryptojournal@v1.2.5-0.20171102134152-f578b3d788ab/src/lib/mail/email.go (about)

     1  package mail
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  // Email represents an email to be sent.
     8  type Email struct {
     9  	Recipients []string
    10  	ReplyTo    string
    11  	Subject    string
    12  	Body       string
    13  	Template   string
    14  	Layout     string
    15  }
    16  
    17  // New returns a new email with the default tenplates and the given recipient.
    18  func New(r string) *Email {
    19  	e := &Email{
    20  		Layout:   "lib/mail/views/layout.html.got",
    21  		Template: "lib/mail/views/template.html.got",
    22  	}
    23  	e.Recipients = append(e.Recipients, r)
    24  	return e
    25  }
    26  
    27  // String returns a formatted string representation for debug.
    28  func (e *Email) String() string {
    29  	return fmt.Sprintf("email to:%v from:%s subject:%s\n\n%s", e.Recipients, e.ReplyTo, e.Subject, e.Body)
    30  }
    31  
    32  // Invalid returns true if this email is not ready to send.
    33  func (e *Email) Invalid() bool {
    34  	return (e.ReplyTo == "" || e.Subject == "" || e.Body == "")
    35  }