func TestAmazonSESSend(t *testing.T) {
	endpoint := os.Getenv("AWS_ENDPOINT")
	accessKeyID := os.Getenv("AWS_ACCESS_KEY_ID")
	secretAccessKey := os.Getenv("AWS_SECRET_ACCESS_KEY")
	from := os.Getenv("EMAIL_FROM")
	to := os.Getenv("EMAIL_TO")

	sender := email.NewAmazonSESSender(endpoint, accessKeyID, secretAccessKey)()

	data := struct {
		Title string
		Items []string
	}{
		Title: "Test page",
		Items: []string{
			"First Item",
			"Second Item",
		},
	}

	body := email.NewFileBasedHTMLTemplateMessageBody("test-html-template.tpl", data)
	err := sender.Send(email.NewMessage(from, to, "Test Email from AmazonSESSender", body))

	if err != nil {
		t.Fatalf("send failed; %v", err)
	}
}
예제 #2
0
func TestSMTPSend(t *testing.T) {
	server := os.Getenv("SMTP_HOST")
	port, _ := strconv.Atoi(os.Getenv("SMTP_PORT"))
	username := os.Getenv("SMTP_USERNAME")
	password := os.Getenv("SMTP_PASSWORD")
	from := os.Getenv("EMAIL_FROM")
	to := os.Getenv("EMAIL_TO")

	sender := email.NewSMTPSender(server, port, username, password)()

	body := email.NewSimpleMessageBody("Simple Message Body")
	err := sender.Send(email.NewMessage(from, to, "Test Email from SMTPSender", body))

	if err != nil {
		t.Fatalf("send failed; %v", err)
	}
}