本文整理汇总了Golang中github.com/jordan-wright/email.Email类的典型用法代码示例。如果您正苦于以下问题:Golang Email类的具体用法?Golang Email怎么用?Golang Email使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Email类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ParseMail
// ParseMail takes in an HTTP Request and returns an Email object
// TODO: This function will likely be changed to take in a []byte
func ParseMail(r *http.Request) (email.Email, error) {
e := email.Email{}
m, err := mail.ReadMessage(r.Body)
if err != nil {
fmt.Println(err)
}
body, err := ioutil.ReadAll(m.Body)
e.HTML = body
return e, err
}
开发者ID:StrangeUSB,项目名称:gophish,代码行数:12,代码来源:util.go
示例2: Send
// Send sends an email Message.
func (m *Mailer) Send(msg *email.Email) error {
err := msg.Send(
m.Address,
m.Auth,
)
if err != nil {
return errors.New("Error sending email: " + err.Error())
}
return nil
}
开发者ID:no2key,项目名称:postman,代码行数:12,代码来源:mail.go
示例3: NotifyEmail
func NotifyEmail(cfg *Config, o *Object, r *Revision) error {
var (
e *email.Email
err error
)
// First version.
if r.Version == 1 {
e, err = newObjectEmail(cfg, o)
} else {
e, err = changedObjectEmail(cfg, o, r)
}
if err != nil {
return err
}
q := bson.M{
"subscribed": true,
}
p := bson.M{
"email": 1,
}
var subs []*Subscriber
if err = cfg.Mongo.Subscribers().Find(q).Select(p).All(&subs); err != nil {
return err
}
// No subscribers.
if len(subs) == 0 {
return nil
}
e.From = cfg.SMTP.From
e.To = make([]string, 1)
for _, sub := range subs {
e.To[0] = sub.Email
if err = e.Send(cfg.SMTP.Addr(), cfg.SMTP.Auth()); err != nil {
log.Printf("error sending email: %s", err)
}
}
return nil
}
开发者ID:chop-dbhi,项目名称:scds,代码行数:49,代码来源:notify.go
示例4: SendEmail
// SendEmail connects to an email server at host:port and sends an email from
// address from, to address to, with subject line subject with message body.
func SendEmail(username string, password string, host string, port int, to []string, subject string, body string) error {
auth := smtp.PlainAuth("", username, password, host)
addr := host + ":" + strconv.Itoa(port)
message := email.Email{
From: username,
To: to,
Subject: subject,
Text: []byte(body),
}
if err := message.Send(addr, auth); err != nil {
return errors.Trace(err)
}
return nil
}
开发者ID:hack4impact,项目名称:transcribe4all,代码行数:17,代码来源:utils.go
示例5: Send
// Send an email using the given host and SMTP auth (optional), returns any
// error thrown by smtp.SendMail. This function merges the To, Cc, and Bcc
// fields and calls the smtp.SendMail function using the Email.Bytes() output as
// the message.
func Send(e *email.Email, addr, username, password string) error {
// Merge the To, Cc, and Bcc fields
to := make([]string, 0, len(e.To)+len(e.Cc)+len(e.Bcc))
to = append(append(append(to, e.To...), e.Cc...), e.Bcc...)
// Check to make sure there is at least one recipient and one "From" address
if e.From == "" || len(to) == 0 {
return errors.New("Must specify at least one From address and one To address")
}
from, err := mail.ParseAddress(e.From)
if err != nil {
return err
}
raw, err := e.Bytes()
if err != nil {
return err
}
return SendMail(addr, username, password, from.Address, to, raw)
}
开发者ID:noblehng,项目名称:bosun,代码行数:22,代码来源:notify.go
示例6: processCampaign
func processCampaign(c *models.Campaign) {
Logger.Printf("Worker received: %s", c.Name)
err := c.UpdateStatus(models.CAMPAIGN_IN_PROGRESS)
if err != nil {
Logger.Println(err)
}
e := email.Email{
Subject: c.Template.Subject,
From: c.SMTP.FromAddress,
}
var auth smtp.Auth
if c.SMTP.Username != "" && c.SMTP.Password != "" {
auth = smtp.PlainAuth("", c.SMTP.Username, c.SMTP.Password, strings.Split(c.SMTP.Host, ":")[0])
}
f, err := mail.ParseAddress(c.SMTP.FromAddress)
if err != nil {
Logger.Println(err)
}
ft := f.Name
if ft == "" {
ft = f.Address
}
for _, t := range c.Results {
td := struct {
models.Result
URL string
TrackingURL string
Tracker string
From string
}{
t,
c.URL + "?rid=" + t.RId,
c.URL + "/track?rid=" + t.RId,
"<img src='" + c.URL + "/track?rid=" + t.RId + "'/>",
ft,
}
// Parse the templates
var subjBuff bytes.Buffer
var htmlBuff bytes.Buffer
var textBuff bytes.Buffer
tmpl, err := template.New("html_template").Parse(c.Template.HTML)
if err != nil {
Logger.Println(err)
}
err = tmpl.Execute(&htmlBuff, td)
if err != nil {
Logger.Println(err)
}
e.HTML = htmlBuff.Bytes()
tmpl, err = template.New("text_template").Parse(c.Template.Text)
if err != nil {
Logger.Println(err)
}
err = tmpl.Execute(&textBuff, td)
if err != nil {
Logger.Println(err)
}
e.Text = textBuff.Bytes()
tmpl, err = template.New("text_template").Parse(c.Template.Subject)
if err != nil {
Logger.Println(err)
}
err = tmpl.Execute(&subjBuff, td)
if err != nil {
Logger.Println(err)
}
e.Subject = string(subjBuff.Bytes())
Logger.Println("Creating email using template")
e.To = []string{t.Email}
Logger.Printf("Sending Email to %s\n", t.Email)
err = e.Send(c.SMTP.Host, auth)
if err != nil {
Logger.Println(err)
err = t.UpdateStatus(models.ERROR)
if err != nil {
Logger.Println(err)
}
} else {
err = t.UpdateStatus(models.EVENT_SENT)
if err != nil {
Logger.Println(err)
}
err = c.AddEvent(models.Event{Email: t.Email, Message: models.EVENT_SENT})
if err != nil {
Logger.Println(err)
}
}
}
err = c.UpdateStatus(models.CAMPAIGN_EMAILS_SENT)
if err != nil {
Logger.Println(err)
}
}
开发者ID:666jfox777,项目名称:gophish,代码行数:93,代码来源:worker.go
示例7: SendTestEmail
func SendTestEmail(s *models.SendTestEmailRequest) error {
e := email.Email{
Subject: s.Template.Subject,
From: s.SMTP.FromAddress,
}
var auth smtp.Auth
if s.SMTP.Username != "" && s.SMTP.Password != "" {
auth = smtp.PlainAuth("", s.SMTP.Username, s.SMTP.Password, strings.Split(s.SMTP.Host, ":")[0])
}
f, err := mail.ParseAddress(s.SMTP.FromAddress)
if err != nil {
Logger.Println(err)
return err
}
ft := f.Name
if ft == "" {
ft = f.Address
}
Logger.Println("Creating email using template")
// Parse the templates
var subjBuff bytes.Buffer
var htmlBuff bytes.Buffer
var textBuff bytes.Buffer
tmpl, err := template.New("html_template").Parse(s.Template.HTML)
if err != nil {
Logger.Println(err)
}
err = tmpl.Execute(&htmlBuff, s)
if err != nil {
Logger.Println(err)
}
e.HTML = htmlBuff.Bytes()
tmpl, err = template.New("text_template").Parse(s.Template.Text)
if err != nil {
Logger.Println(err)
}
err = tmpl.Execute(&textBuff, s)
if err != nil {
Logger.Println(err)
}
e.Text = textBuff.Bytes()
tmpl, err = template.New("text_template").Parse(s.Template.Subject)
if err != nil {
Logger.Println(err)
}
err = tmpl.Execute(&subjBuff, s)
if err != nil {
Logger.Println(err)
}
e.Subject = string(subjBuff.Bytes())
e.To = []string{s.Email}
Logger.Printf("Sending Email to %s\n", s.Email)
err = e.Send(s.SMTP.Host, auth)
if err != nil {
Logger.Println(err)
// For now, let's split the error and return
// the last element (the most descriptive error message)
serr := strings.Split(err.Error(), ":")
return errors.New(serr[len(serr)-1])
}
return err
}
开发者ID:666jfox777,项目名称:gophish,代码行数:62,代码来源:worker.go
示例8: processCampaign
func processCampaign(c *models.Campaign) {
Logger.Printf("Worker received: %s", c.Name)
err := c.UpdateStatus(models.CAMPAIGN_IN_PROGRESS)
if err != nil {
Logger.Println(err)
}
e := email.Email{
Subject: c.Template.Subject,
From: c.SMTP.FromAddress,
}
var auth smtp.Auth
if c.SMTP.Username != "" && c.SMTP.Password != "" {
auth = smtp.PlainAuth("", c.SMTP.Username, c.SMTP.Password, strings.Split(c.SMTP.Host, ":")[0])
}
ips, err := net.InterfaceAddrs()
if err != nil {
Logger.Println(err)
}
for _, i := range ips {
Logger.Println(i.String())
}
for _, t := range c.Results {
td := struct {
models.Result
URL string
Tracker string
TrackingURL string
}{
t,
"http://" + ips[0].String() + "?rid=" + t.RId,
"<img src='http://" + ips[0].String() + "/track?rid=" + t.RId + "'/>",
"http://" + ips[0].String() + "/track?rid=" + t.RId,
}
// Parse the templates
var subjBuff bytes.Buffer
var htmlBuff bytes.Buffer
var textBuff bytes.Buffer
tmpl, err := template.New("html_template").Parse(c.Template.HTML)
if err != nil {
Logger.Println(err)
}
err = tmpl.Execute(&htmlBuff, td)
if err != nil {
Logger.Println(err)
}
e.HTML = htmlBuff.Bytes()
tmpl, err = template.New("text_template").Parse(c.Template.Text)
if err != nil {
Logger.Println(err)
}
err = tmpl.Execute(&textBuff, td)
if err != nil {
Logger.Println(err)
}
e.Text = textBuff.Bytes()
tmpl, err = template.New("text_template").Parse(c.Template.Subject)
if err != nil {
Logger.Println(err)
}
err = tmpl.Execute(&subjBuff, td)
if err != nil {
Logger.Println(err)
}
e.Subject = string(subjBuff.Bytes())
Logger.Println("Creating email using template")
e.To = []string{t.Email}
Logger.Printf("Sending Email to %s\n", t.Email)
err = e.Send(c.SMTP.Host, auth)
if err != nil {
Logger.Println(err)
err = t.UpdateStatus("Error")
if err != nil {
Logger.Println(err)
}
} else {
err = t.UpdateStatus(models.EVENT_SENT)
if err != nil {
Logger.Println(err)
}
}
time.Sleep(1)
}
}
开发者ID:atsuyim,项目名称:gophish,代码行数:83,代码来源:worker.go
示例9: processCampaign
func processCampaign(c *models.Campaign) {
Logger.Printf("Worker received: %s", c.Name)
err := c.UpdateStatus(models.CAMPAIGN_IN_PROGRESS)
if err != nil {
Logger.Println(err)
}
e := email.Email{
Subject: c.Template.Subject,
From: c.SMTP.FromAddress,
}
var auth smtp.Auth
if c.SMTP.Username != "" && c.SMTP.Password != "" {
auth = smtp.PlainAuth("", c.SMTP.Username, c.SMTP.Password, strings.Split(c.SMTP.Host, ":")[0])
}
tc := &tls.Config{
ServerName: c.SMTP.Host,
InsecureSkipVerify: c.SMTP.IgnoreCertErrors,
}
f, err := mail.ParseAddress(c.SMTP.FromAddress)
if err != nil {
Logger.Println(err)
}
ft := f.Name
if ft == "" {
ft = f.Address
}
for _, t := range c.Results {
td := struct {
models.Result
URL string
TrackingURL string
Tracker string
From string
}{
t,
c.URL + "?rid=" + t.RId,
c.URL + "/track?rid=" + t.RId,
"<img src='" + c.URL + "/track?rid=" + t.RId + "'/>",
ft,
}
// Parse the templates
var subjBuff bytes.Buffer
var htmlBuff bytes.Buffer
var textBuff bytes.Buffer
tmpl, err := template.New("html_template").Parse(c.Template.HTML)
if err != nil {
Logger.Println(err)
}
err = tmpl.Execute(&htmlBuff, td)
if err != nil {
Logger.Println(err)
}
e.HTML = htmlBuff.Bytes()
tmpl, err = template.New("text_template").Parse(c.Template.Text)
if err != nil {
Logger.Println(err)
}
err = tmpl.Execute(&textBuff, td)
if err != nil {
Logger.Println(err)
}
e.Text = textBuff.Bytes()
tmpl, err = template.New("text_template").Parse(c.Template.Subject)
if err != nil {
Logger.Println(err)
}
err = tmpl.Execute(&subjBuff, td)
if err != nil {
Logger.Println(err)
}
e.Subject = string(subjBuff.Bytes())
Logger.Println("Creating email using template")
e.To = []string{t.Email}
// Attach the files
for _, a := range c.Template.Attachments {
decoder := base64.NewDecoder(base64.StdEncoding, strings.NewReader(a.Content))
_, err = e.Attach(decoder, a.Name, a.Type)
if err != nil {
Logger.Println(err)
}
}
Logger.Printf("Sending Email to %s\n", t.Email)
err = e.SendWithTLS(c.SMTP.Host, auth, tc)
if err != nil {
Logger.Println(err)
es := struct {
Error string `json:"error"`
}{
Error: err.Error(),
}
ej, err := json.Marshal(es)
if err != nil {
Logger.Println(err)
}
err = t.UpdateStatus(models.ERROR)
if err != nil {
Logger.Println(err)
}
err = c.AddEvent(models.Event{Email: t.Email, Message: models.EVENT_SENDING_ERROR, Details: string(ej)})
if err != nil {
//.........这里部分代码省略.........
开发者ID:pluckljn,项目名称:gophish,代码行数:101,代码来源:worker.go
示例10: SendTestEmail
func SendTestEmail(s *models.SendTestEmailRequest) error {
e := email.Email{
Subject: s.Template.Subject,
From: s.SMTP.FromAddress,
}
var auth smtp.Auth
if s.SMTP.Username != "" && s.SMTP.Password != "" {
auth = smtp.PlainAuth("", s.SMTP.Username, s.SMTP.Password, strings.Split(s.SMTP.Host, ":")[0])
}
t := &tls.Config{
ServerName: s.SMTP.Host,
InsecureSkipVerify: s.SMTP.IgnoreCertErrors,
}
f, err := mail.ParseAddress(s.SMTP.FromAddress)
if err != nil {
Logger.Println(err)
return err
}
ft := f.Name
if ft == "" {
ft = f.Address
}
Logger.Println("Creating email using template")
// Parse the templates
var subjBuff bytes.Buffer
var htmlBuff bytes.Buffer
var textBuff bytes.Buffer
tmpl, err := template.New("html_template").Parse(s.Template.HTML)
if err != nil {
Logger.Println(err)
}
err = tmpl.Execute(&htmlBuff, s)
if err != nil {
Logger.Println(err)
}
e.HTML = htmlBuff.Bytes()
tmpl, err = template.New("text_template").Parse(s.Template.Text)
if err != nil {
Logger.Println(err)
}
err = tmpl.Execute(&textBuff, s)
if err != nil {
Logger.Println(err)
}
e.Text = textBuff.Bytes()
tmpl, err = template.New("text_template").Parse(s.Template.Subject)
if err != nil {
Logger.Println(err)
}
err = tmpl.Execute(&subjBuff, s)
if err != nil {
Logger.Println(err)
}
e.Subject = string(subjBuff.Bytes())
e.To = []string{s.Email}
// Attach the files
for _, a := range s.Template.Attachments {
decoder := base64.NewDecoder(base64.StdEncoding, strings.NewReader(a.Content))
_, err = e.Attach(decoder, a.Name, a.Type)
if err != nil {
Logger.Println(err)
}
}
Logger.Printf("Sending Email to %s\n", s.Email)
err = e.SendWithTLS(s.SMTP.Host, auth, t)
if err != nil {
Logger.Println(err)
// For now, let's split the error and return
// the last element (the most descriptive error message)
serr := strings.Split(err.Error(), ":")
return errors.New(serr[len(serr)-1])
}
return err
}
开发者ID:pluckljn,项目名称:gophish,代码行数:74,代码来源:worker.go
注:本文中的github.com/jordan-wright/email.Email类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论