This repository was archived by the owner on May 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathses_test.go
82 lines (66 loc) · 1.74 KB
/
ses_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2013 SourceGraph, Inc.
// Copyright 2011-2013 Numrotron Inc.
// Use of this source code is governed by an MIT-style license
// that can be found in the LICENSE file.
package ses
import (
"encoding/base64"
"flag"
"fmt"
"testing"
)
var to, from string
func init() {
flag.StringVar(&to, "to", "[email protected]", "email recipient")
flag.StringVar(&from, "from", "", "email sender")
}
func checkFlags(t *testing.T) {
if len(from) == 0 {
t.Fatal("must specify sender via -from flag.")
}
}
func TestSendEmail(t *testing.T) {
checkFlags(t)
_, err := EnvConfig.SendEmail(from, to, "amzses text test", textBody)
if err != nil {
t.Fatal(err)
}
}
func TestSendEmailHTML(t *testing.T) {
checkFlags(t)
_, err := EnvConfig.SendEmailHTML(from, to, "amzses html test", textBody, htmlBody)
if err != nil {
t.Fatal(err)
}
}
func TestSendRawEmail(t *testing.T) {
checkFlags(t)
attachment := base64.StdEncoding.EncodeToString([]byte(textBody))
raw := `To: %s
From: %s
Subject: amzses raw test
Content-Type: multipart/mixed; boundary="_003_97DCB304C5294779BEBCFC8357FCC4D2"
MIME-Version: 1.0
--_003_97DCB304C5294779BEBCFC8357FCC4D2
Content-Type: text/plain;
%s
--_003_97DCB304C5294779BEBCFC8357FCC4D2
Content-Type: text/plain; name="test.txt"
Content-Description: test.txt
Content-Disposition: attachment; filename="test.txt"; size=%d;
Content-Transfer-Encoding: base64
%s
--_003_97DCB304C5294779BEBCFC8357FCC4D2
`
_, err := EnvConfig.SendRawEmail([]byte(fmt.Sprintf(raw, to, from, textBody, len(attachment), attachment)))
if err != nil {
t.Fatal(err)
}
}
var textBody = `This is an example email body for the amzses go package.`
var htmlBody = `
This is an <b>html email</b>.
<br/>
<br/>
<img src="http://placehold.it/600x200/">
`