Esempio n. 1
0
func sendEmail(gun m.Mailgun, address string, msg string, htmlMsg string) {
	message := gun.NewMessage("David Pfahler <*****@*****.**>", "[Monitor]: Uni-Webseite hat sich geändert", msg, address)
	message.SetHtml(htmlMsg)
	response, id, _ := gun.Send(message)
	fmt.Printf("Response ID: %s\n", id)
	fmt.Printf("Message from server: %s\n", response)
}
Esempio n. 2
0
// Tries to locate the first stored event type, returning the associated stored message key.
func findStoredMessageID(mg mailgun.Mailgun) (string, error) {
	ei := mg.NewEventIterator()
	err := ei.GetFirstPage(mailgun.GetEventsOptions{})
	for {
		if err != nil {
			return "", err
		}
		if len(ei.Events()) == 0 {
			break
		}
		for _, event := range ei.Events() {
			if event["event"] == "stored" {
				s := event["storage"].(map[string]interface{})
				k := s["key"]
				return k.(string), nil
			}
		}
		err = ei.GetNext()
	}
	return "", fmt.Errorf("No stored messages found.  Try changing MG_EMAIL_TO to an address that stores messages and try again.")
}
func StartHttpServer(mg mailgun.Mailgun, config Config) {
	http.HandleFunc("/subscribe", func(response http.ResponseWriter, request *http.Request) {
		email := request.FormValue("email")

		newMember := mailgun.Member{
			Address:    email,
			Subscribed: mailgun.Subscribed,
		}

		mg.CreateMember(true, config.MailingListAddress, newMember)

		fmt.Println(email + " has been subscribed to the mailing list")

		http.Redirect(response, request, config.RedirectUrlAfterSubscribe, http.StatusTemporaryRedirect)
	})

	http.HandleFunc("/health-check", func(response http.ResponseWriter, request *http.Request) {
		fmt.Fprintf(response, "Running")
	})

	http.ListenAndServe(":"+strconv.Itoa(config.HttpPort), nil)
}
Esempio n. 4
0
func teardown(t *testing.T, mg mailgun.Mailgun, address string) {
	err := mg.DeleteList(address)
	if err != nil {
		t.Fatal(err)
	}
}