Esempio n. 1
0
func newObjectEmail(cfg *Config, o *Object) (*email.Email, error) {
	var (
		err  error
		byt  []byte
		buff bytes.Buffer
	)

	cxt := EmailContext{
		Time:       time.Unix(o.Time, 0).Local(),
		Key:        o.Key,
		Version:    o.Version,
		URL:        fmt.Sprintf("http://%s/objects/%s", cfg.HTTP.Addr(), o.Key),
		VersionURL: fmt.Sprintf("http://%s/objects/%s/v/%d", cfg.HTTP.Addr(), o.Key, o.Version),
	}

	byt, _ = yaml.Marshal(o.Value)
	cxt.Object = string(byt)

	if err = notifyTemplate.Lookup("new-object").Execute(&buff, &cxt); err != nil {
		return nil, err
	}

	e := email.NewEmail()

	e.Subject = "[SCDS] New Object"
	e.Text = buff.Bytes()

	return e, nil
}
Esempio n. 2
0
func (self mailerImpl) Send(mail Mail) error {
	e := email.NewEmail()
	if mail.From != "" {
		e.From = mail.From
	} else {
		e.From = self.cfg.Email
	}
	e.To = mail.To
	e.Cc = mail.Cc
	e.Bcc = mail.Bcc
	e.Subject = mail.Subject
	e.HTML = []byte(mail.Body)

	for _, attachment := range mail.Attachments {
		e.AttachFile(attachment)
	}

	hostAndPort := strings.Join([]string{
		self.cfg.Host,
		strconv.Itoa(self.cfg.Port),
	}, ":")

	plainAuth := smtp.PlainAuth(
		"", // identity
		self.cfg.Email,
		self.cfg.Password,
		self.cfg.Host,
	)

	return e.Send(hostAndPort, plainAuth)
}
Esempio n. 3
0
func (t *Thing) EmailParticipants() error {
	if len(t.Participants) == 0 {
		return nil
	}

	showurl := fmt.Sprint(URL_ROOT, "/show/", t.Id)
	editurl := fmt.Sprint(URL_ROOT, "/edit/", t.Id)

	e := email.NewEmail()
	e.From = t.Owner.Email
	e.To = []string{}
	for _, p := range t.Participants {
		if !p.Done {
			e.To = append(e.To, p.Email)
		}
	}
	e.Subject = "A friendly reminder..."
	e.Text = []byte(fmt.Sprintf(texttempl, t.Owner.Email, showurl, t.ThingName, t.ThingLink, editurl))
	e.HTML = []byte(blackfriday.MarkdownBasic(e.Text))
	fmt.Printf("%v\n", e.To)
	println(string(e.Text))

	return e.Send("MAILHOST:25", nil)
	//	return nil

}
Esempio n. 4
0
File: main.go Progetto: zlyang/lab
func main() {
	resp, err := http.Get("http://www.cnblogs.com/jasondan/p/3497757.html")
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	content, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}

	doc, err := goquery.NewDocumentFromReader(bytes.NewReader(content))
	if err != nil {
		log.Fatal(err)
	}

	header := ""
	doc.Find(`.postTitle`).Each(func(i int, s *goquery.Selection) {
		header = strings.TrimSpace(s.Text())
	})

	e := email.NewEmail()
	e.From = "cnblogs <*****@*****.**>"
	e.To = []string{sendTo}
	e.Subject = header
	e.HTML = []byte(content)
	e.Send("smtp.163.com:25", smtp.PlainAuth("", sendFrom, sendFromPassword, "smtp.163.com"))
}
Esempio n. 5
0
func (m *Mail) constructMessage() ([]byte, error) {
	message := email.NewEmail()
	message.From = m.From
	message.To = []string{m.To}
	message.Subject = m.Subject
	message.HTML = []byte(m.Body)
	return message.Bytes()
}
Esempio n. 6
0
// send email to user
func sendEmail(contents []byte) {
	e := email.NewEmail()
	e.From = config.Mail["from"]
	e.To = []string{config.Mail["to"]}
	e.Subject = mailSubject + todayString()

	e.HTML = contents
	e.Send(config.Mail["host"]+":587", smtp.PlainAuth("", config.Mail["user"], config.Mail["password"], config.Mail["host"]))
}
func sendEmail(username string, password string, release string, file string) error {
	e := email.NewEmail()
	e.From = "Releases <*****@*****.**>"
	e.To = []string{"*****@*****.**"}
	e.Subject = fmt.Sprintf("Data Dictionary was generated for %s.", release)
	e.Text = []byte("Please see attached.")
	e.AttachFile(file)
	err := e.Send("smtp.gmail.com:587", smtp.PlainAuth("", username, password, "smtp.gmail.com"))
	return err
}
Esempio n. 8
0
// Replace this localhost version with your appropriate mail function
// https://github.com/jordan-wright/email#email
func sendMail(recipient, message string) {
	e := email.NewEmail()

	// Change From to something more appropriate
	e.From = recipient
	e.To = []string{recipient}
	e.Subject = message

	err := e.Send("localhost:25", nil)
	if err != nil {
		log.Fatal(err)
	}
}
func ViaEmail(to, from, subject, text, html string) *handshakejserrors.LogicError {
	e := email.NewEmail()
	e.From = from
	e.To = []string{to}
	e.Subject = subject
	e.Text = []byte(text)
	e.HTML = []byte(html)

	err := e.Send(SMTP_ADDRESS+":"+SMTP_PORT, smtp.PlainAuth("", SMTP_USERNAME, SMTP_PASSWORD, SMTP_ADDRESS))
	if err != nil {
		logic_error := &handshakejserrors.LogicError{"unknown", "", err.Error()}
		return logic_error
	}

	return nil
}
Esempio n. 10
0
func (n *Notification) DoEmail(subject, body []byte, c *Conf, ak string, attachments ...*models.Attachment) {
	e := email.NewEmail()
	e.From = c.EmailFrom
	for _, a := range n.Email {
		e.To = append(e.To, a.Address)
	}
	e.Subject = string(subject)
	e.HTML = body
	for _, a := range attachments {
		e.Attach(bytes.NewBuffer(a.Data), a.Filename, a.ContentType)
	}
	e.Headers.Add("X-Bosun-Server", util.Hostname)
	if err := Send(e, c.SMTPHost, c.SMTPUsername, c.SMTPPassword); err != nil {
		collect.Add("email.sent_failed", nil, 1)
		slog.Errorf("failed to send alert %v to %v %v\n", ak, e.To, err)
		return
	}
	collect.Add("email.sent", nil, 1)
	slog.Infof("relayed alert %v to %v sucessfully. Subject: %d bytes. Body: %d bytes.", ak, e.To, len(subject), len(body))
}
Esempio n. 11
0
func changedObjectEmail(cfg *Config, o *Object, r *Revision) (*email.Email, error) {
	var (
		err  error
		byt  []byte
		buff bytes.Buffer
	)

	cxt := EmailContext{
		Time:       time.Unix(r.Time, 0).Local(),
		Key:        o.Key,
		Version:    r.Version,
		URL:        fmt.Sprintf("http://%s/objects/%s", cfg.HTTP.Addr(), o.Key),
		VersionURL: fmt.Sprintf("http://%s/objects/%s/v/%d", cfg.HTTP.Addr(), o.Key, r.Version),
	}

	if r.Changes != nil {
		byt, _ = yaml.Marshal(r.Changes)
		cxt.Changes = string(byt)
	}

	if r.Additions != nil {
		byt, _ = yaml.Marshal(r.Additions)
		cxt.Additions = string(byt)
	}

	if r.Removals != nil {
		byt, _ = yaml.Marshal(r.Removals)
		cxt.Removals = string(byt)
	}

	if err = notifyTemplate.Lookup("changed-object").Execute(&buff, &cxt); err != nil {
		return nil, err
	}

	e := email.NewEmail()

	e.Subject = "[SCDS] Object Changed"
	e.Text = buff.Bytes()

	return e, nil
}
Esempio n. 12
0
// 发送
func (this *Email) Send(address []string, title string, html string) error {
	e := email.NewEmail()
	e.From = conf.ConfInstance.EmailFrom
	e.To = address
	e.Subject = title
	e.Text = []byte("邮件无法显示")
	e.HTML = []byte(`
		<div style="border-bottom:3px solid #d9d9d9; background:url(http://www.wokugame.com/static/img/email_bg.gif) repeat-x 0 1px;">
			<div style="border:1px solid #c8cfda; padding:40px;">
				` + html + `
				<p>&nbsp;</p>
				<div>我酷游戏团队 祝您游戏愉快</div>
				<div>Powered by wokugame</div>
				<img src="http://www.wokugame.com/static/img/logo.png">
				</div>
			</div>
		</div>
	`)
	return e.Send(conf.ConfInstance.EmailHost+":"+strconv.Itoa(conf.ConfInstance.EmailPort),
		smtp.PlainAuth("", conf.ConfInstance.EmailFrom, conf.ConfInstance.EmailPassword, conf.ConfInstance.EmailHost))
}
Esempio n. 13
0
func main() {
	m := email.NewEmail()
	m.From = "System Alert <*****@*****.**>"
	m.To = []string{"Quang <*****@*****.**>"}
	m.AttachFile("/tmp/backup.txt")
	server := "smtp.zoho.com:465"
	passwd := "random-pwd"

	m.Subject = "[System Alert] Backup system is finish\n\n"
	m.Text = []byte("Hi all \n\n" +
		"Backup on server 10.20.30.100 is done. Plz see attachment.\n\n" +
		"--\n" +
		"bot")

	err := m.Send(server, smtp.PlainAuth("", "*****@*****.**", passwd, server))

	if err != nil {
		log.Fatal(err)
	}

	log.Print("sent, visit http://www.nhindeogi.com")
}