1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| package email
import ( "github.com/jordan-wright/email" )
type EType int
type AddrType int
const ( QQ EType = iota )
type SendUtil struct { From string To string Subject string Text string Attach *Attach MyInfo *User ToCC []string ToBCC []string addr string host string se *email.Email cce *email.Email bcce *email.Email }
type Attach struct { fileBytes []byte fileName string fileType string }
func NewAttach(fileBytes []byte, fileName string, fileType string) *Attach { return &Attach{fileBytes: fileBytes, fileName: fileName, fileType: fileType} }
type User struct { Identity string Username string Password string }
func NewUser(identity string, username string, password string) *User { return &User{Identity: identity, Username: username, Password: password} }
func NewBCCSendUtil(from string, to string, subject string, text string, attach *Attach, myInfo *User, ToBCC []string, t EType) *SendUtil { e := &SendUtil{From: from, To: to, Subject: subject, Text: text, Attach: attach, MyInfo: myInfo, ToBCC: ToBCC} switchType(t, e) return e }
func NewCCSendUtil(from string, to string, subject string, text string, attach *Attach, myInfo *User, ToCC []string, t EType) *SendUtil { e := &SendUtil{From: from, To: to, Subject: subject, Text: text, Attach: attach, MyInfo: myInfo, ToCC: ToCC} switchType(t, e) return e }
func NewSimpleSendUtil(from string, to string, subject string, text string, attach *Attach, myInfo *User, t EType) *SendUtil { e := &SendUtil{From: from, To: to, Subject: subject, Text: text, Attach: attach, MyInfo: myInfo} switchType(t, e) return e }
func switchType(t EType, e *SendUtil) { switch t { case QQ: e.addr = "smtp.qq.com:25" e.host = "smtp.qq.com" break } }
|