Пример #1
0
func SendMail(attachment []byte, filename string) error {
	from := C.MailFrom
	to := []string{C.MailTo}
	subject := "convert file " + filename

	msg := message.NewMultipartMessage("mixed", "")
	att := message.NewBinaryMessage(bytes.NewBuffer(attachment))
	att.SetHeader("Content-Type", "application/octet-stream; charset=utf-8")
	att.SetHeader("Content-Disposition", `attachment; filename*= UTF-8''`+filename)
	msg.AddPart(att)
	msg.SetHeader("From", from)
	msg.SetHeader("Subject", subject)
	msg.SetHeader("To", to[0])
	body, err := ioutil.ReadAll(msg)
	if err != nil {
		return err
	}
	auth := smtp.PlainAuth("", C.MailUsername, C.MailPassword, C.MailSmtpHost)
	err = smtp.SendMail(C.MailSmtpHost+":"+C.MailSmtpPort, auth, from, to, body)
	return err
}
Пример #2
0
func Send(attachment []byte, filename string) error {
	from := acc.from
	to := []string{acc.to}
	subject := "convert file " + filename

	msg := message.NewMultipartMessage("mixed", "")
	att := message.NewBinaryMessage(bytes.NewBuffer(attachment))
	att.SetHeader("Content-Type", "application/octet-stream; name="+filename)
	att.SetHeader("Content-Disposition", "attachment; filename="+filename)
	msg.AddPart(att)
	msg.SetHeader("From", from)
	msg.SetHeader("Subject", subject)
	msg.SetHeader("To", to[0])
	body, err := ioutil.ReadAll(msg)
	if err != nil {
		return err
	}

	auth := smtp.PlainAuth("", acc.username, acc.password, acc.smtpHost)
	err = smtp.SendMail(acc.smtpHost+":"+acc.port, auth, from, to, body)
	return err
}