Documentation ¶
Index ¶
- func RecipientsHeader(recipients []mail.Address) string
- type AttachOption
- type Attachment
- type Letter
- type WriteOption
- func Attach(r io.Reader, filename string, opts ...AttachOption) (WriteOption, error)
- func AttachFile(path, filename string, opts ...AttachOption) (WriteOption, error)
- func BCC(name, addr string) WriteOption
- func BCCAddress(addresses ...mail.Address) WriteOption
- func CC(name, addr string) WriteOption
- func CCAddress(addresses ...mail.Address) WriteOption
- func Content(text, html string) WriteOption
- func From(name, addr string) WriteOption
- func FromAddress(addr mail.Address) WriteOption
- func HTML(content string) WriteOption
- func Must(opt WriteOption, err error) WriteOption
- func MustAttach(r io.Reader, filename string, opts ...AttachOption) WriteOption
- func MustAttachFile(path, filename string, opts ...AttachOption) WriteOption
- func Subject(s string) WriteOption
- func Text(content string) WriteOption
- func To(name, addr string) WriteOption
- func ToAddress(addresses ...mail.Address) WriteOption
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RecipientsHeader ¶
RecipientsHeader builds the mail header value for the given recipients.
Types ¶
type AttachOption ¶
type AttachOption func(*Attachment)
AttachOption is an attachment option.
func ContentType ¶
func ContentType(ct string) AttachOption
ContentType sets the "Content-Type" header of an attachment.
type Attachment ¶
type Attachment struct { Filename string Header textproto.MIMEHeader ContentType string Content []byte }
Attachment is a file attachment.
type Letter ¶
type Letter struct { Subject string From mail.Address To []mail.Address CC []mail.Address BCC []mail.Address Text string HTML string Attachments []Attachment }
Letter represents a mail.
func Write ¶
func Write(opts ...WriteOption) Letter
Write builds a letter with the provided options.
Example ¶
package main import ( "bytes" "github.com/bounoable/postdog/letter" ) func main() { let := letter.Write( letter.From("Bob", "bob@belcher.test"), letter.To("Calvin", "calvin@fishoeder.test"), letter.To("Felix", "felix@fishoeder.test"), letter.BCC("Jimmy", "jimmy@pesto.test"), letter.Subject("Hi, buddy."), letter.Text("Have a drink later?"), letter.HTML("Have a <strong>drink</strong> later?"), letter.MustAttach(bytes.NewReader([]byte("tasty")), "burgerrecipe.txt", letter.ContentType("text/plain")), ) _ = let }
Output:
type WriteOption ¶
type WriteOption func(*Letter)
WriteOption configures a letter.
func Attach ¶
func Attach(r io.Reader, filename string, opts ...AttachOption) (WriteOption, error)
Attach attaches the content of r to a letter, with the given filename. It returns an error if it fails to read from r. Available options:
ContentType(): Set the attachment's "Content-Type" header.
func AttachFile ¶
func AttachFile(path, filename string, opts ...AttachOption) (WriteOption, error)
AttachFile attaches the file at path to a letter, with the given filename. It returns an error if it fails to read the file. Available options:
ContentType(): Set the attachment's "Content-Type" header.
func BCC ¶
func BCC(name, addr string) WriteOption
BCC adds a recipient to the "BCC" field of a letter.
func BCCAddress ¶
func BCCAddress(addresses ...mail.Address) WriteOption
BCCAddress adds a recipient to the "BCC" field of a letter.
func CCAddress ¶
func CCAddress(addresses ...mail.Address) WriteOption
CCAddress adds a recipient to the "CC" field of a letter.
func Content ¶
func Content(text, html string) WriteOption
Content sets both the HTML and text body of a letter.
func FromAddress ¶
func FromAddress(addr mail.Address) WriteOption
FromAddress sets the "From" field of a letter.
func Must ¶
func Must(opt WriteOption, err error) WriteOption
Must returns opt if err is nil and panics otherwise.
func MustAttach ¶
func MustAttach(r io.Reader, filename string, opts ...AttachOption) WriteOption
MustAttach does the same as Attach(), but panic if Attach() returns an error.
func MustAttachFile ¶
func MustAttachFile(path, filename string, opts ...AttachOption) WriteOption
MustAttachFile does the same as AttachFile(), but panics if AttachFile() returns an error.
func ToAddress ¶
func ToAddress(addresses ...mail.Address) WriteOption
ToAddress adds a recipient to the "To" field of a letter.