Example #1
0
// sendEmail sends an email notification. Event specifies which notification to
// send. Valid choices are EVENT_ (see template.go).
func sendEmail(job *database.Job, event string) {
	mailServer := database.GetMailServer()

	htmlMessage := message(job, database.NotificationServiceEmail, event, TypeHTML)
	txtMessage := message(job, database.NotificationServiceEmail, event, TypeText)
	subject := emailSubject(job, event)
	recipient := mail.Address{
		Name:    job.Name,
		Address: job.Email,
	}

	message := gophermail.Message{
		From:     mailServer.From(),
		To:       []mail.Address{recipient},
		Subject:  subject,
		Body:     txtMessage,
		HTMLBody: htmlMessage,
	}

	err := gophermail.SendMail(mailServer.Server(), mailServer.Auth(), &message)

	if err != nil {
		log.Println(err)
	}
}
Example #2
0
// Send sends an email Message.
func (m *Mailer) Send(msg *Message) error {
	err := gophermail.SendMail(
		m.Address,
		m.Auth,
		msg.msg,
	)
	if err != nil {
		return errors.New("Error sending email: " + err.Error())
	}

	return nil
}
func (m *SmtpMail) SendMail(addr string, a smtp.Auth, from string, to []string, subject string, msg []byte) error {
	log.Println("Sending Email:", subject)
	log.Println("Email Server:", addr)

	toAddress := make([]mail.Address, 1)
	toAddress[0].Address = to[0]

	message := gophermail.Message{}
	message.To = toAddress
	message.SetFrom(from)
	message.Subject = subject
	message.HTMLBody = string(msg)

	return gophermail.SendMail(addr, a, &message)
}
Example #4
0
// SendMail connects to the SMTP server supplied in mc and sends an email.
func (mc *MailConfig) SendMail(msg *gmail.Message) error {
	auth := smtp.PlainAuth(mc.Identity, mc.Username, mc.Password, mc.Host)
	return gmail.SendMail(mc.Host+":"+mc.Port, auth, msg)
}