예제 #1
0
파일: postmark.go 프로젝트: masom/doorbot
func (p *Postmark) AccountCreated(person *doorbot.Person, password string) error {
	log.WithFields(log.Fields{
		"account_id":   p.Account.ID,
		"person_id":    person.ID,
		"person_email": person.Email,
	}).Info("Notificator::Mailgun->AccountCreated")

	message := &postmark.Message{
		From:    "*****@*****.**", //TODO make this a configuration value
		To:      person.Email,
		Subject: "Doorbot - Account Created",
		TextBody: fmt.Sprintf(
			"Welcome %s,\n\nYou can log in on the dashboard using this temporary password: %s\n\n\nAccount: %d\nTemporary Host: %s\n Email: %s\nPassword: %s\n\n- Doorbot",
			person.Name, password, p.Account.ID, p.Account.Host, person.Email, password,
		),
	}

	pm := postmark.NewPostmark(p.Token)
	_, err := pm.Send(message)

	if err != nil {
		log.WithFields(log.Fields{
			"account_id":   p.Account.ID,
			"person_id":    person.ID,
			"person_email": person.Email,
		}).Error("Notificator::EmailNotifier->AccountCreated error")

		return err
	}

	return nil
}
예제 #2
0
func main() {

	apiKey := os.Getenv("POSTMARK_API")
	if len(apiKey) <= 0 {
		fmt.Println("Set the POSTMARK_API environment varible to run this demo")
		os.Exit(1)
	}
	p := postmark.NewPostmark(apiKey)
	r, e := p.Send(&postmark.Message{
		From:     "*****@*****.**",
		To:       "*****@*****.**",
		Subject:  "Test postmark",
		TextBody: "Hello World!"})

	if e != nil {
		fmt.Println("ERROR: ", e.String())
		os.Exit(1)
	}
	fmt.Println("Response :", r.String())
}
예제 #3
0
파일: postmark.go 프로젝트: masom/doorbot
// KnockKnock sends a private message to a user.
func (p *Postmark) KnockKnock(d *doorbot.Door, person *doorbot.Person) error {
	log.WithFields(log.Fields{
		"account_id": p.Account.ID,
		"person_id":  person.ID,
		"door_id":    d.ID,
	}).Info("Notificator::Postmark->KnockKnock request")

	dbb := rendering.DoorbotBar()

	renderingData := map[string]string{
		"name": person.Name,
		"door": d.Name,
	}

	//TODO HTML message template.
	message := &postmark.Message{
		From:     "*****@*****.**",
		To:       person.Email,
		Subject:  dbb.Render("Doorbot - There is someone waiting at the {{door}}.", renderingData),
		TextBody: dbb.Render("Hi {{name}},\nThere is someone waiting at the {{door}}.\n\n - Doorbot", renderingData),
	}

	pm := postmark.NewPostmark(p.Token)

	_, err := pm.Send(message)

	if err != nil {
		log.WithFields(log.Fields{
			"error":      err,
			"account_id": p.Account.ID,
			"person_id":  person.ID,
			"door_id":    d.ID,
		}).Error("Notificator::Postmark->KnockKnock error")
		return err
	}

	return nil
}