Documentation ¶
Index ¶
Examples ¶
Constants ¶
const ( // SparkPost driver type. SparkPost = "sparkpost" // MailGun driver type. MailGun = "mailgun" // SendGrid driver type. SendGrid = "sendgrid" // SMTP driver type. SMTP = "smtp" )
const ( // SparkAPIVersion defines the default API version for // SparkPost. SparkAPIVersion = 1 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attachment ¶
Attachment defines the mail file that has been uploaded via the forms endpoint. It contains useful information for sending files over the mail driver.
func (Attachment) B64 ¶
func (a Attachment) B64() string
Returns the base 64 encode of the byte data.
type Attachments ¶
type Attachments []Attachment
Attachments defines the slice of mail attachments.
func (Attachments) Exists ¶
func (a Attachments) Exists() bool
Determines if there are any attachments in the slice.
type Config ¶
type Config struct { URL string APIKey string Domain string FromAddress string FromName string Password string Port int }
Config represents the configuration passed when a new client is constructed. FromAddress, FromName and an APIKey are all required to create a new client.
type Mailer ¶
type Mailer interface {
Send(t *Transmission) (Response, error)
}
Mailer defines the sender for go-mail returning a Response or error when an email is sent.
func NewClient ¶
NewClient
Creates a new Mailer based on the input driver. Sparkpost, MailGun or SendGrid can be passed. Returns an error if a driver did not match, Or there was an error creating the client.
Example ¶
Docs
mailer, err := NewClient(SparkPost, Config{ APIKey: "my-key", FromAddress: "hello@test.com", FromName: "Test", }) if err != nil { fmt.Println(err) } fmt.Println(mailer)
Output:
type Response ¶
type Response struct { StatusCode int // e.g. 200 Body string // e.g. {"result: success"} Headers map[string][]string // e.g. map[X-Ratelimit-Limit:[600]] ID string // e.g "100" Message interface{} // e.g "Email sent successfully" }
Response represents the data passed back from a successful transmission. Where possible, a status code, body, headers will be returned within the response.
type Transmission ¶
type Transmission struct { Recipients []string Subject string HTML string PlainText string Attachments Attachments }
Transmission represents the JSON structure accepted by and returned from the driver's API. Recipients, HTML and a subject is required to send the email.
func (*Transmission) Validate ¶
func (t *Transmission) Validate() error
Validate runs sanity checks of a Transmission struct. This is run before any email sending to ensure there are no invalid API calls.