Пример #1
1
func SendMail(body string) error {
	e := &EmailDetails{
		os.Getenv("EMAIL_USERNAME"),
		os.Getenv("EMAIL_PASSWORD"),
		os.Getenv("EMAIL_TWO"),
	}

	m := gomail.NewMessage()

	m.SetHeader("From", e.EmailUsername)
	m.SetHeader("To", e.EmailUsername, e.EmailTwo)
	m.SetHeader("Subject", "New Message from Davillex.com!")
	m.SetBody("text/html", body)

	d := gomail.NewPlainDialer("smtp.gmail.com", 587, e.EmailUsername, e.EmailPassword)

	err := d.DialAndSend(m)

	return err
}
Пример #2
0
//Send sends an Email
func (s *SMTPEmailService) Send(recipients []string, subject string, message string) (err error) {
	gomsg := gomail.NewMessage()
	gomsg.SetHeader("Subject", subject)
	gomsg.SetHeader("From", "*****@*****.**")
	gomsg.SetHeader("To", recipients...)
	gomsg.SetBody("text/html", message)
	err = s.dialer.DialAndSend(gomsg)
	if err != nil {
		log.Error("Failed to send email ", err)
	}
	return
}
Пример #3
0
func (self *Email) Notify(body string, attachments [][]*multipart.FileHeader) {

	m := gomail.NewMessage()
	m.SetHeader("From", self.From)

	m.SetHeader("To", strings.Split(self.To, ",")...)

	if self.CC != "" {
		m.SetHeader("CC", strings.Split(self.CC, ",")...)
	}

	m.SetHeader("Subject", self.Title)
	m.SetBody(self.ContentType, body)

	for _, tmp := range attachments {
		for _, attachment := range tmp {
			f, err := attachment.Open()
			if err != nil {
				log.Panic(err)
			}

			defer f.Close()
			m.Attach(attachment.Filename,
				gomail.SetCopyFunc(func(w io.Writer) error {
					_, err := io.Copy(w, f)
					return err
				}),
			)
		}
	}

	port, err := strconv.Atoi(self.SMTP["port"].(string))

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

	d := gomail.NewPlainDialer(
		self.SMTP["host"].(string),
		port,
		self.SMTP["user"].(string),
		self.SMTP["password"].(string),
	)

	// Send the email to Bob, Cora and Dan.
	if err := d.DialAndSend(m); err != nil {
		log.Panic(err)
	}

}
Пример #4
0
func send_mail(content []byte) {
	m := gomail.NewMessage()
	m.SetHeader("From", "*****@*****.**")
	m.SetHeader("To", "*****@*****.**")
	m.SetHeader("Subject", "Hello!")
	m.SetBody("text/html",
		"<h1>Result</h1>"+
			"<p>"+string(content)+"</p>")
	d := gomail.NewDialer("smtp.mail.com", 465, "*****@*****.**", "****")
	if err := d.DialAndSend(m); err != nil {
		log.Error("Mail send faild!")
		panic(fmt.Sprintf("Mailing failed! (%s)", err))
	}
}
Пример #5
0
func (dm *Daemon) sendMsg(from, to, subject, body string, isHtml bool) error {
	if dm.closed {
		return ErrMailChannelClosed
	}
	m := gomail.NewMessage()
	m.SetHeader("From", from)
	m.SetHeader("To", to)
	m.SetHeader("Subject", subject)
	contentType := "text/plain"
	if isHtml {
		contentType = "text/html"
	}
	m.SetBody(contentType, body)
	dm.Send(m)
	return nil
}
Пример #6
0
func main() {
	http.HandleFunc("/sync", func(w http.ResponseWriter, r *http.Request) {
		r.ParseForm()
		title := r.Form.Get("title")
		body := r.Form.Get("body")

		if strings.EqualFold(title, "") {
			w.Write(response(false, "please pass the title"))
			return
		}

		if strings.EqualFold(body, "") {
			w.Write(response(false, "please pass the body"))
			return
		}

		m := gomail.NewMessage()
		m.SetHeader("From", "*****@*****.**")
		m.SetHeader("To", "*****@*****.**", "*****@*****.**")
		m.SetHeader("Subject", title)
		m.SetBody("text/plain", body)
		attachMutex.Lock()
		defer attachMutex.Unlock()
		fp, err := os.Create(attach)
		if err != nil {
			panic(err)
		}
		defer func() {
			fp.Close()
			os.Remove(attach)
		}()
		fp.Write([]byte(body))
		m.Attach(attach)

		d := gomail.NewPlainDialer("smtp.163.com", 25, "user", "password")

		if err := d.DialAndSend(m); err != nil {
			panic(err)
		}
		w.Write(response(true, "data sync success"))
	})
	err := http.ListenAndServe(":2225", nil)
	if err != nil {
		panic(err)
	}

}
Пример #7
0
func SendSimpleMessage(to, text, url string) {
	var cidimage = strings.Split(url, "\\")
	fmt.Print(cidimage[len(cidimage)-1])
	m := gomail.NewMessage()
	m.SetHeader("From", "*****@*****.**")
	m.SetHeader("To", to)
	m.SetHeader("Subject", "Hello!")
	m.Embed(url)
	m.SetBody("text/html", "<html>  <body>"+text+"<img src=cid:"+cidimage[len(cidimage)-1]+" style=width:128px;height:128px;>  </body></html> ")

	d := gomail.NewPlainDialer("smtp.gmail.com", 587, "*****@*****.**", "cgvm0234")

	// Send the email to Bob, Cora and Dan.
	if err := d.DialAndSend(m); err != nil {
		panic(err)
	}
}
Пример #8
0
func sendEmail(Body, Sender, Subject, sentTo string) error {

	msg := gomail.NewMessage()
	msg.SetHeader("From", Sender)
	msg.SetHeader("To", sentTo)
	msg.SetAddressHeader("Cco", config.SendCopy, config.SendName)
	msg.SetHeader("Subject", Subject)
	msg.SetBody("text/plain", Body)

	mailer := gomail.NewPlainDialer(config.SmtpServer, config.SmptPort, config.SmtpUser, config.SmtpToken)

	if err := mailer.DialAndSend(msg); err != nil {
		return errBadMail
	}

	return nil
}
Пример #9
0
func (this *Mail) Dial(host string, port int, username, password string) {
	this.dialer = gomail.Dialer{Host: host, Port: port, Auth: smtp.PlainAuth("", username, password, host)}
	this.message = gomail.NewMessage()
}
Пример #10
0
// to "[email protected];[email protected]" //
func SendDefaultMail(to string) (err error) {
	userInfo := getMailUser()
	if userInfo.SmtpServer == "" {
		return

	}

	// to = "*****@*****.**"
	rand.Seed(time.Now().UnixNano())
	m := gomail.NewMessage()
	m.SetHeader("From", userInfo.User)
	m.SetHeader("To", to)
	m.SetHeader("Subject", getMailTitle(to))
	// getMailContent(to)

	tmpAJpg := imageModify("a.jpg")
	tmpBJpg := imageModify("b.jpg")
	tmpCJpg := imageModify("c.jpg")
	tmpDJpg := imageModify("d.jpg")
	m.Embed(tmpAJpg)
	m.Embed(tmpBJpg)
	m.Embed(tmpCJpg)
	m.Embed(tmpDJpg)
	// "Hello <b>Bob</b> and <i>Cora</i>!"
	m.SetBody("text/html",
		fmt.Sprintf(
			`[%d]
新店开业,每天首单免单,第2-10单5折。记得联系客服哦。
[%d]  <br/>
        <table>
          <tr>
            <td>
              <a href="https://item.taobao.com/item.htm?id=524586665791">
                <img width="300" height="300" src="cid:tmp-a.jpg" />
              </a>
            </td>
            <td>
              <a href="https://item.taobao.com/item.htm?id=520985240078">
                <img width="300" height="300" src="cid:tmp-b.jpg" />
              </a>
            </td>
          </tr>
          <tr>
            <td>
              <a href="https://item.taobao.com/item.htm?id=524586665791">
                     淘宝爆款莫代尔家居睡衣 束腰修身无缝美体衣保暖内衣女款套装[%d]
              </a><br/>
            </td>
            <td>
              <a href="https://item.taobao.com/item.htm?id=520985240078">
                   2015莫代尔打底衫女秋冬款圆领长袖女T恤<br/>通勤中长款修身纯色[%d]
              </a><br/>
            </td>
          </tr>
        </table>
        <table>
          <tr>
            <td>
              <a href="https://item.taobao.com/item.htm?id=524465659854">
                <img width="300" height="300" src="cid:tmp-c.jpg" />
              </a>
            </td>
            <td>
              <a href="https://item.taobao.com/item.htm?id=524372966855">
                <img width="300" height="300" src="cid:tmp-d.jpg" />
              </a>
            </td>
          </tr>
          <tr>
            <td>
              <a href="https://item.taobao.com/item.htm?id=524465659854">
                    热销纯棉保暖内衣套装女士款 玫瑰提花蕾丝衣领薄款塑身秋衣秋裤
              </a><br/>
            </td>
            <td>
              <a href="https://item.taobao.com/item.htm?id=524372966855">
                 加厚锦纶高腰黄金暖宫发热护腰踩脚外穿一体裤打底裤女冬季
              </a><br/>
            </td>
          </tr>
        </table>

`, rand.Intn(1000),
			rand.Intn(1000),
			rand.Intn(1000),
			rand.Intn(1000)))

	d := gomail.NewPlainDialer(userInfo.SmtpServer, userInfo.User, userInfo.Pass, userInfo.Port)

	fmt.Println("send_mail", userInfo.User, to)
	if err := d.DialAndSend(m); err != nil {
		fmt.Println("err,,,", err)
	}
	return
}