forked from sendgrid/sendgrid-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMailTest.java
More file actions
174 lines (165 loc) · 10.7 KB
/
MailTest.java
File metadata and controls
174 lines (165 loc) · 10.7 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package com.sendgrid;
import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
public class MailTest {
@Test
public void testHelloWorld() throws IOException {
Mail mail = new Mail()
.subject("Sending with SendGrid is Fun")
.from(new Email()
.email("[email protected]")
).to(new Email()
.email("[email protected]")
).content(new Content()
.type(ContentType.TEXT_PLAIN)
.value("and easy to do anywhere, even with Java")
);
Assert.assertEquals(mail.build(),
"{\"from\":{\"email\":\"[email protected]\"},\"subject\":\"Sending with SendGrid is Fun\",\"personalizations\":[{\"to\":[{\"email\":\"[email protected]\"}]}],\"content\":[{\"type\":\"text/plain\",\"value\":\"and easy to do anywhere, even with Java\"}]}");
}
@Test
public void testKitchenSink() throws IOException {
Mail mail = new Mail()
.from(new Email()
.name("Example User")
.email("[email protected]")
).replyTo(new Email()
.name("Example User")
.email("[email protected]")
).subject("Hello World from the SendGrid Java Library")
.personalization(new Personalization()
.to(new Email()
.name("Example User")
.email("[email protected]")
).to(new Email()
.name("Example User")
.email("[email protected]")
).cc(new Email()
.name("Example User")
.email("[email protected]")
).cc(new Email()
.name("Example User")
.email("[email protected]")
).bcc(new Email()
.name("Example User")
.email("[email protected]")
).bcc(new Email()
.name("Example User")
.email("[email protected]")
).subject("Hello World from the Personalized SendGrid Java Library")
.header("X-Test", "test")
.header("X-Mock", "true")
.substitution("%name%", "Example User")
.substitution("%city%", "Denver")
.customArg("user_id", "343")
.customArg("type", "marketing")
.sendAt(1443636843)
).personalization(new Personalization()
.to(new Email()
.name("Example User")
.email("[email protected]")
).to(new Email()
.name("Example User")
.email("[email protected]")
).cc(new Email()
.name("Example User")
.email("[email protected]")
).cc(new Email()
.name("Example User")
.email("[email protected]")
).bcc(new Email()
.name("Example User")
.email("[email protected]")
).bcc(new Email()
.name("Example User")
.email("[email protected]")
).subject("Hello World from the Personalized SendGrid Java Library")
.header("X-Test", "test")
.header("X-Mock", "true")
.substitution("%name%", "Example User")
.substitution("%city%", "Denver")
.customArg("user_id", "343")
.customArg("type", "marketing")
.sendAt(1443636843)
).content(new Content()
.type(ContentType.TEXT_PLAIN)
.value("some text here")
).content(new Content()
.type(ContentType.TEXT_HTML)
.value("<html><body>some text here</body></html>")
).attachment(new Attachment()
.content("TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12")
.type(ContentType.APPLICATION_PDF)
.filename("balance_001.pdf")
.disposition("attachment")
.contentId("Balance Sheet")
).attachment(new Attachment()
.content("BwdW")
.type(ContentType.IMAGE_PNG)
.filename("banner.png")
.disposition("inline")
.contentId("Banner")
).templateId("13b8f94f-bcae-4ec6-b752-70d6cb59f932")
.section("%section1%", "Substitution Text for Section 1")
.section("%section2%", "Substitution Text for Section 2")
.header("X-Test1", "1")
.header("X-Test2", "2")
.category("May")
.category("2016")
.customArg("campaign", "welcome")
.customArg("weekday", "morning")
.sendAt(1443636842)
.asm(new ASM()
.groupId(99)
.groupsToDisplay(new int[] { 4, 5, 6, 7, 8 })
).ipPoolId("23")
.mailSettings(new MailSettings()
.bccSettings(new BCCSettings()
.enable(true)
.email("[email protected]")
).sandboxMode(new Setting()
.enable(true)
).bypassListManagement(new Setting()
.enable(true)
).footerSettings(new FooterSettings()
.enable(true)
.text("Footer Text")
.html("<html><body>Footer Text</body></html>")
).spamCheckSettings(new SpamCheckSettings()
.enable(true)
.spamThreshold(1)
.postToUrl("https://spamcatcher.sendgrid.com")
)
).trackingSettings(new TrackingSettings()
.clickTrackingSettings(new ClickTrackingSettings()
.enable(true)
.enableText(true)
).openTrackingSettings(new OpenTrackingSettings()
.enable(true)
.substitutionTag("Optional tag to replace with the open image in the body of the message")
).subscriptionTrackingSetting(new SubscriptionTrackingSettings()
.enable(true)
.text("text to insert into the text/plain portion of the message")
.html("<html><body>html to insert into the text/html portion of the message</body></html>")
.substitutionTag("Optional tag to replace with the open image in the body of the message")
).googleAnalyticsSettings(new GoogleAnalyticsSettings()
.enable(true)
.campaignSource("some source")
.campaignTerm("some term")
.campaignContent("some content")
.campaignName("some name")
.campaignMedium("some medium")
)
);
Assert.assertEquals(mail.build(),
"{\"from\":{\"name\":\"Example User\",\"email\":\"[email protected]\"},\"subject\":\"Hello World from the SendGrid Java Library\",\"personalizations\":[{\"to\":[{\"name\":\"Example User\",\"email\":\"[email protected]\"},{\"name\":\"Example User\",\"email\":\"[email protected]\"}],\"cc\":[{\"name\":\"Example User\",\"email\":\"[email protected]\"},{\"name\":\"Example User\",\"email\":\"[email protected]\"}],\"bcc\":[{\"name\":\"Example User\",\"email\":\"[email protected]\"},{\"name\":\"Example User\",\"email\":\"[email protected]\"}],\"subject\":\"Hello World from the Personalized SendGrid Java Library\",\"headers\":{\"X-Mock\":\"true\",\"X-Test\":\"test\"},\"substitutions\":{\"%city%\":\"Denver\",\"%name%\":\"Example User\"},\"custom_args\":{\"type\":\"marketing\",\"user_id\":\"343\"},\"send_at\":1443636843},{\"to\":[{\"name\":\"Example User\",\"email\":\"[email protected]\"},{\"name\":\"Example User\",\"email\":\"[email protected]\"}],\"cc\":[{\"name\":\"Example User\",\"email\":\"[email protected]\"},{\"name\":\"Example User\",\"email\":\"[email protected]\"}],\"bcc\":[{\"name\":\"Example User\",\"email\":\"[email protected]\"},{\"name\":\"Example User\",\"email\":\"[email protected]\"}],\"subject\":\"Hello World from the Personalized SendGrid Java Library\",\"headers\":{\"X-Mock\":\"true\",\"X-Test\":\"test\"},\"substitutions\":{\"%city%\":\"Denver\",\"%name%\":\"Example User\"},\"custom_args\":{\"type\":\"marketing\",\"user_id\":\"343\"},\"send_at\":1443636843}],\"content\":[{\"type\":\"text/plain\",\"value\":\"some text here\"},{\"type\":\"text/html\",\"value\":\"<html><body>some text here</body></html>\"}],\"attachments\":[{\"content\":\"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12\",\"type\":\"application/pdf\",\"filename\":\"balance_001.pdf\",\"disposition\":\"attachment\",\"content_id\":\"Balance Sheet\"},{\"content\":\"BwdW\",\"type\":\"image/png\",\"filename\":\"banner.png\",\"disposition\":\"inline\",\"content_id\":\"Banner\"}],\"template_id\":\"13b8f94f-bcae-4ec6-b752-70d6cb59f932\",\"sections\":{\"%section1%\":\"Substitution Text for Section 1\",\"%section2%\":\"Substitution Text for Section 2\"},\"headers\":{\"X-Test1\":\"1\",\"X-Test2\":\"2\"},\"categories\":[\"May\",\"2016\"],\"custom_args\":{\"campaign\":\"welcome\",\"weekday\":\"morning\"},\"send_at\":1443636842,\"asm\":{\"group_id\":99,\"groups_to_display\":[4,5,6,7,8]},\"ip_pool_name\":\"23\",\"mail_settings\":{\"bcc\":{\"enable\":true,\"email\":\"[email protected]\"},\"bypass_list_management\":{\"enable\":true},\"footer\":{\"enable\":true,\"text\":\"Footer Text\",\"html\":\"<html><body>Footer Text</body></html>\"},\"sandbox_mode\":{\"enable\":true},\"spam_check\":{\"enable\":true,\"threshold\":1,\"post_to_url\":\"https://spamcatcher.sendgrid.com\"}},\"tracking_settings\":{\"click_tracking\":{\"enable\":true,\"enable_text\":true},\"open_tracking\":{\"enable\":true,\"substitution_tag\":\"Optional tag to replace with the open image in the body of the message\"},\"subscription_tracking\":{\"enable\":true,\"text\":\"text to insert into the text/plain portion of the message\",\"html\":\"<html><body>html to insert into the text/html portion of the message</body></html>\",\"substitution_tag\":\"Optional tag to replace with the open image in the body of the message\"},\"ganalytics\":{\"enable\":true,\"utm_source\":\"some source\",\"utm_term\":\"some term\",\"utm_content\":\"some content\",\"utm_campaign\":\"some name\",\"utm_medium\":\"some medium\"}},\"reply_to\":{\"name\":\"Example User\",\"email\":\"[email protected]\"}}");
}
@Test
public void fromShouldReturnCorrectFrom() {
Mail mail = new Mail();
Email from = new Email();
mail.from(from);
Assert.assertSame(from, mail.getFrom());
}
}