github.com/admpub/mail@v0.0.0-20170408110349-d63147b0317b/README.md (about)

     1  # mail
     2  Golang SMTP电子邮件包
     3  
     4  # 安装
     5  ```go
     6  go get github.com/admpub/mail
     7  ```
     8  
     9  # 例子
    10  ```go
    11  import (
    12    "fmt"
    13    "github.com/admpub/mail"
    14    "os"
    15  )
    16  
    17  func main() {
    18    conf := &mail.SMTPConfig{
    19        Username: "admpub",
    20        Password: "",
    21        Host:     "smtp.admpub.com",
    22        Port:     587,
    23        Secure:   "SSL",
    24    }
    25    c := mail.NewSMTPClient(conf)
    26    m := mail.NewMail()
    27    m.AddTo("hello@admpub.com") //或 "老弟 <hello@admpub.com>"
    28    m.AddFrom("hank@admpub.com") //或 "老哥 <hank@admpub.com>"
    29    m.AddSubject("Testing")
    30    m.AddText("Some text :)")
    31    filepath, _ := os.Getwd()
    32    m.AddAttachment(filepath + "/mail.go")
    33    if e := c.Send(m); e != nil {
    34      fmt.Println(e)
    35    } else {
    36      fmt.Println("发送成功")
    37    }
    38  }
    39  ```