Metrics
0
Watch 118 Star 509 Fork 129

GVPdreamans / syncdGoMIT

Sign up for free
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
syncd是一款开源的代码部署工具,它具有简单、高效、易用等特点,可以提高团队的工作效率. spread retract

https://syncd.cc

  • Go 50.1%
  • Vue 39.4%
  • JavaScript 7.8%
  • CSS 1.7%
  • HTML 0.6%
  • Other 0.4%
Clone or download
sendmail.go 1.78 KB
Copy Edit Web IDE Raw Blame History
dreamans authored 2019-03-24 22:33 . feature 2.0
// Copyright 2019 syncd Author. All Rights Reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package syncd
import (
"strings"
"gopkg.in/gomail.v2"
)
type SendMail struct {
Enable int
Smtp string
Port int
User string
Pass string
dialer *gomail.Dialer
}
func NewSendMail(mail *SendMail) *SendMail {
mail.dialer = gomail.NewPlainDialer(mail.Smtp, mail.Port, mail.User, mail.Pass)
return mail
}
func (mail *SendMail) send(msg *SendMailMessage) error {
if mail.Enable == 0 {
return nil
}
msg.mail = mail
m := msg.NewMessage()
if err := mail.dialer.DialAndSend(m); err != nil {
return err
}
return nil
}
func (mail *SendMail) Send(msg *SendMailMessage) {
if err := mail.send(msg); err != nil {
App.Logger.Error(
"send mail failed, to[%s], cc[%s], subject[%s]",
strings.Join(msg.To, ","),
strings.Join(msg.Cc, ","),
msg.Subject,
)
}
}
func (mail *SendMail) AsyncSend(msg *SendMailMessage) {
go mail.Send(msg)
}
type SendMailMessage struct {
From string
To []string
Cc []string
Subject string
Body string
Attach string
mail *SendMail
}
func (m *SendMailMessage) NewMessage() *gomail.Message {
mailMsg := gomail.NewMessage()
if m.From == "" {
mailMsg.SetHeader("From", m.mail.User)
} else {
mailMsg.SetHeader("From", m.From)
}
mailMsg.SetHeader("To", m.To...)
if len(m.Cc) > 0 {
mailMsg.SetHeader("Cc", m.Cc...)
}
mailMsg.SetHeader("Subject", m.Subject)
mailMsg.SetBody("text/html", m.Body)
if m.Attach != "" {
mailMsg.Attach(m.Attach)
}
return mailMsg
}

Comment ( 0 )

You need to Sign in for post a comment

Help Search