Documentation ¶
Overview ¶
Package email provides sending email ability.
Index ¶
- func Attachment(fd io.Reader, filename string) fw.Option
- func Bcc(bcc ...string) fw.Option
- func Cc(cc ...string) fw.Option
- func From(from string) fw.Option
- func HTMLContentType() fw.Option
- func LoginAuth(username, password string) smtp.Auth
- func NewSender(smtpServer string, auth smtp.Auth, opt ...fw.Option) (sender fw.Sender, err error)
- func PoolSize(size int) fw.Option
- func ServerName(name string) fw.Option
- func Subject(subject string) fw.Option
- func SubjectFunc(fn func() string) fw.Option
- func TextContentType() fw.Option
- func Timeout(timeout time.Duration) fw.Option
- func To(to ...string) fw.Option
- type Email
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Attachment ¶
Attachment sets email attachment.
func NewSender ¶
NewSender returns Sender which sends email. requires SMTP server address, like "smtp.gmail.com:587", smtp.Auth which you have to implements and defines how get throug authorization.
func SubjectFunc ¶
SubjectFunc sets email subject from the func returned.
Types ¶
type Email ¶
type Email struct {
// contains filtered or unexported fields
}
Email implements Sender which sends email.
func (*Email) Send ¶
Send sends email which you have to provides io.Reader include message body, and few options which implements Option.
Example (Html) ¶
package main import ( "log" "strings" fw "github.com/LiangXianSen/firewheel" "github.com/LiangXianSen/firewheel/sender/email" ) func main() { var err error var sender fw.Sender if sender, err = email.NewSender( "smtp.gmail.com:587", email.LoginAuth("username", "password"), ); err != nil { log.Fatal(err) } if err = sender.Send( strings.NewReader("<h1>Fancy HTML is supported, too!</h1>"), email.HTMLContentType(), email.Subject("email test"), email.From("test@gmail.com"), email.To("test@gmail.com", "example@gmail.com"), email.Bcc("example@gmail.com"), email.Cc("example@gmail.com"), ); err != nil { log.Fatal(err) } }
Output:
Example (Text) ¶
package main import ( "log" "strings" fw "github.com/LiangXianSen/firewheel" "github.com/LiangXianSen/firewheel/sender/email" ) func main() { var err error var sender fw.Sender if sender, err = email.NewSender( "smtp.gmail.com:587", email.LoginAuth("username", "password"), ); err != nil { log.Fatal(err) } if err = sender.Send( strings.NewReader("test message"), email.TextContentType(), email.Subject("email test"), email.From("test@gmail.com"), email.To("test@gmail.com", "example@gmail.com"), email.Bcc("example@gmail.com"), email.Cc("example@gmail.com"), ); err != nil { log.Fatal(err) } }
Output:
Click to show internal directories.
Click to hide internal directories.