Skip to content

Commit 05bbb6e

Browse files
Merge pull request #4 from ryan-lydz/master
AMP functionality
2 parents 0579a4d + 2026042 commit 05bbb6e

File tree

17 files changed

+322
-68
lines changed

17 files changed

+322
-68
lines changed

examples/build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ version '1.0-SNAPSHOT'
88
sourceCompatibility = 1.8
99

1010
repositories {
11+
mavenLocal()
1112
mavenCentral()
1213
}
1314

1415
dependencies {
1516
testCompile group: 'junit', name: 'junit', version: '4.12'
16-
compile 'com.fasterxml.jackson.core:jackson-core:2.9.8'
17-
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.8'
18-
compile group: 'com.socketlabs', name: 'injectionApi', version: '1.0.5'
17+
compile 'com.fasterxml.jackson.core:jackson-core:2.11.0'
18+
compile 'com.fasterxml.jackson.core:jackson-databind:2.11.0'
19+
compile group: 'com.socketlabs', name: 'injectionApi', version: '1.1.0-SNAPSHOT'
1920
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
#Thu Jun 18 12:46:49 EDT 2020
2+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-all.zip
13
distributionBase=GRADLE_USER_HOME
24
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-bin.zip
4-
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6+
zipStoreBase=GRADLE_USER_HOME

examples/src/main/java/examples/Main.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ private static void DisplayTheMenu() {
7070
System.out.println(" 17: Bulk Send From DataSource With Merge Data ");
7171
System.out.println(" 18: Bulk Send Complex Example ");
7272
System.out.println();
73+
System.out.println(" AMP Html Examples: ");
74+
System.out.println(" 19: Basic Send With Amp Body Example ");
75+
System.out.println(" 20: Bulk Send With Amp Body Example ");
76+
System.out.println();
7377
System.out.println("-------------------------------------------------------------------------");
7478
}
7579

@@ -102,6 +106,8 @@ private static String GetExampleName(String selection) {
102106
case 16: return "examples.bulk.BulkSendWithASCIICharsetMergeData";
103107
case 17: return "examples.bulk.BulkSendFromDataSourceWithMerge";
104108
case 18: return "examples.bulk.BulkSendComplexExample";
109+
case 19: return "examples.basic.BasicSendWithAmpBodyExample";
110+
case 20: return "examples.bulk.BulkSendWithAmpBodyExample";
105111
default:
106112
System.out.println("Invalid Input (Out of Range)");
107113
return null;

examples/src/main/java/examples/basic/BasicSend.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import com.socketLabs.injectionApi.message.EmailAddress;
77
import examples.*;
88

9+
import javax.swing.*;
10+
911
public class BasicSend implements Example {
1012

1113
public SendResponse RunExample () throws Exception {
@@ -17,9 +19,8 @@ public SendResponse RunExample () throws Exception {
1719
message.setPlainTextBody("This is the Plain Text Body of my message.");
1820

1921
message.setFrom(new EmailAddress("[email protected]"));
20-
2122
message.addToEmailAddress("[email protected]");
22-
message.addToEmailAddress("[email protected]", "Recipient #1");
23+
message.addToEmailAddress("[email protected]", "Recipient #2");
2324
message.addToEmailAddress(new EmailAddress("[email protected]"));
2425
message.addToEmailAddress(new EmailAddress("[email protected]", "Recipient #4"));
2526

examples/src/main/java/examples/basic/BasicSendComplexExample.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,34 @@ public SendResponse RunExample() throws Exception {
2020

2121
// Build the message
2222
// =========================
23-
2423
BasicMessage message = new BasicMessage();
2524

2625
message.setMessageId("ComplexExample");
2726
message.setMailingId("BasicSend");
2827

29-
message.setSubject("Sending A Complex Test Message (basic Send)");
28+
message.setSubject("Sending A Complex Test Message (Basic Send)");
3029

3130
message.setHtmlBody("<html><body><h1>Sending A Complex Test Message</h1><p>This is the html Body of my message.</p><h2>Embedded Image:</h2><p><img src=\"cid:bus\" /></p></body></html>");
3231
message.setPlainTextBody("This is the Plain Text Body of my message.");
3332

33+
//Setting Amp Body
34+
message.setAmpBody("<!doctype html>" +
35+
"<html amp4email>" +
36+
"<head>" +
37+
" <meta charset=\"utf-8\">" +
38+
" <script async src=\"https://cdn.ampproject.org/v0.js\"></script>" +
39+
" <style amp4email-boilerplate>body{visibility:hidden}</style>" +
40+
" <style amp-custom>" +
41+
" h1 {" +
42+
" margin: 1rem;" +
43+
" }" +
44+
" </style>" +
45+
"</head>" +
46+
"<body>" +
47+
" <h1>This is the AMP Html Body of my message</h1>" +
48+
"</body>" +
49+
"</html>");
50+
3451
message.setFrom(new EmailAddress("[email protected]"));
3552
message.setReplyTo(new EmailAddress("[email protected]"));
3653

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package examples.basic;
2+
3+
import com.socketLabs.injectionApi.SendResponse;
4+
import com.socketLabs.injectionApi.SocketLabsClient;
5+
import com.socketLabs.injectionApi.message.BasicMessage;
6+
import com.socketLabs.injectionApi.message.EmailAddress;
7+
import examples.*;
8+
9+
import javax.swing.*;
10+
11+
public class BasicSendWithAmpBodyExample implements Example {
12+
13+
/*For more information on AMP Html, visit the following link: amp.dev/documentation */
14+
15+
public SendResponse RunExample () throws Exception {
16+
17+
BasicMessage message = new BasicMessage();
18+
19+
message.setSubject("Sending AMP Test Message (Basic Send)");
20+
message.setHtmlBody("<html><body><h1>Sending A Test Message</h1><p>This HTML will show if AMP is not supported.</p></body></html>");
21+
message.setAmpBody("<!doctype html>" +
22+
"<html amp4email>" +
23+
"<head>" +
24+
" <meta charset=\"utf-8\">" +
25+
" <script async src=\"https://cdn.ampproject.org/v0.js\"></script>" +
26+
" <style amp4email-boilerplate>body{visibility:hidden}</style>" +
27+
" <style amp-custom>" +
28+
" h1 {" +
29+
" margin: 1rem;" +
30+
" }" +
31+
" </style>" +
32+
"</head>" +
33+
"<body>" +
34+
" <h1>This is the AMP Html Body of my message</h1>" +
35+
"</body>" +
36+
"</html>");
37+
38+
message.setFrom(new EmailAddress("[email protected]"));
39+
message.addToEmailAddress("[email protected]");
40+
message.addToEmailAddress("[email protected]", "Recipient #2");
41+
message.addToEmailAddress(new EmailAddress("[email protected]"));
42+
message.addToEmailAddress(new EmailAddress("[email protected]", "Recipient #4"));
43+
44+
// create the client
45+
SocketLabsClient client = new SocketLabsClient(ExampleConfig.ServerId, ExampleConfig.ApiKey);
46+
47+
// send the message
48+
SendResponse response = client.send(message);
49+
50+
return response;
51+
52+
}
53+
54+
}

examples/src/main/java/examples/bulk/BulkSendComplexExample.java

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public SendResponse RunExample() throws Exception {
2929

3030
message.setCharSet("UTF-8");
3131

32-
message.setSubject("Complex BulkSend Example");
32+
message.setSubject("Sending A Complex Test Message (Bulk Send)");
3333

3434
// Build the Content (Note the %% symbols used to denote the data to be merged)
3535
String html = "<html>"
@@ -50,8 +50,6 @@ public SendResponse RunExample() throws Exception {
5050
+ " </p>"
5151
+ " <h2>UTF-8 Characters:</h2>"
5252
+ " <p>✔ - Check</p>"
53-
+ " <h2>Embedded Image:</h2>"
54-
+ " <p><img src=\"cid:bus\" /></p>"
5553
+ " </body>"
5654
+ "</html>";
5755
message.setHtmlBody(html);
@@ -66,7 +64,41 @@ public SendResponse RunExample() throws Exception {
6664
+ " Example of Merge Usage"
6765
+ " Our company motto is '%%Motto%%'."
6866
+ " Your birthday is %%Birthday%% and you are %%Age%% years old.";
69-
message.setPlainTextBody(text);
67+
message.setPlainTextBody(text);
68+
69+
String amp = "<!doctype html>"
70+
+ "<html amp4email>"
71+
+ "<head>"
72+
+ "<title>Sending an AMP Test Message</title>"
73+
+ " <meta charset=\"utf-8\">"
74+
+ " <script async src=\"https://cdn.ampproject.org/v0.js\"></script>"
75+
+ " <style amp4email-boilerplate>body{visibility:hidden}</style>"
76+
+ " <style amp-custom>"
77+
+ " h1 {"
78+
+ " margin: 1rem;"
79+
+ " }"
80+
+ " </style>"
81+
+ "</head>"
82+
+ "<body>"
83+
+ " <h1>Sending An AMP Complex Test Message</h1>"
84+
+ " <h2>Merge Data</h2>"
85+
+ " <p>"
86+
+ " Motto = <b>%%Motto%%</b> </br>"
87+
+ " Birthday = <b>%%Birthday%%</b> </br>"
88+
+ " Age = <b>%%Age%%</b> </br>"
89+
+ " UpSell = <b>%%UpSell%%</b>"
90+
+ " </p>"
91+
+ " <h2>Example of Merge Usage</h2>"
92+
+ " <p>"
93+
+ " Our company motto is '<b>%%Motto%%</b>'. </br>"
94+
+ " Your birthday is <b>%%Birthday%%</b> and you are <b>%%Age%%</b> years old."
95+
+ " </p>"
96+
+ " <h2>UTF-8 Characters:</h2>"
97+
+ " <p>✔ - Check</p>"
98+
+ " </body>"
99+
+ " </html>";
100+
101+
message.setAmpBody(amp);
70102

71103
message.setFrom(new EmailAddress("[email protected]", "FromMe"));
72104
message.setReplyTo(new EmailAddress("[email protected]"));
@@ -77,7 +109,7 @@ public SendResponse RunExample() throws Exception {
77109
// Add global merge data using a map
78110
TreeMap<String, String> globalMergeData = new TreeMap<>();
79111
globalMergeData.put("Motto", "When hitting the inbox matters!");
80-
globalMergeData.put("Birthday", "unkown");
112+
globalMergeData.put("Birthday", "unknown");
81113
message.setGlobalMergeData(globalMergeData);
82114

83115
// Add global merge data directly to the Global Merge Data Map on he message
@@ -124,14 +156,6 @@ public SendResponse RunExample() throws Exception {
124156
attachment1.addCustomHeader("Attachment-Header", "I Am A Bus");
125157
message.getAttachments().add(attachment1);
126158

127-
// Add Attachment using the addAttachments function
128-
Attachment attachment2 = new Attachment(
129-
"bus2.png",
130-
"image/png",
131-
"src/main/java/examples/img/bus.png"
132-
);
133-
attachment2.setContentId("bus");
134-
message.addAttachments(attachment2);
135159

136160
// Add Attachment a filePath {string} to the array
137161
message.addAttachments(new Attachment("src/main/java/examples/html/SimpleEmail.html"));
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package examples.bulk;
2+
3+
import com.socketLabs.injectionApi.SendResponse;
4+
import com.socketLabs.injectionApi.SocketLabsClient;
5+
import com.socketLabs.injectionApi.message.BulkMessage;
6+
import com.socketLabs.injectionApi.message.BulkRecipient;
7+
import com.socketLabs.injectionApi.message.EmailAddress;
8+
import examples.*;
9+
10+
public class BulkSendWithAmpBodyExample implements Example {
11+
@Override
12+
13+
/*For more information on AMP Html, visit the following link: amp.dev/documentation */
14+
15+
public SendResponse RunExample() throws Exception {
16+
17+
BulkMessage message = new BulkMessage();
18+
19+
message.setSubject("Sending A Test Message (Bulk Send)");
20+
message.setHtmlBody("<html><body><h1>Sending A Test Message</h1><p>This HTML will show if AMP is not supported.</p></body></html>");
21+
message.setAmpBody("<!doctype html>"
22+
+ "<html amp4email>"
23+
+ "<head>" + " <meta charset=\"utf-8\">"
24+
+ " <script async src=\"https://cdn.ampproject.org/v0.js\"></script>"
25+
+ " <style amp4email-boilerplate>body{visibility:hidden}</style>"
26+
+ " <style amp-custom>"
27+
+ " h1 {"
28+
+ " margin: 1rem;"
29+
+ " }"
30+
+ " </style>"
31+
+ "</head>"
32+
+ "<body>"
33+
+ " <h1>This is the AMP Html Body of my message</h1>"
34+
+ "</body>"
35+
+ "</html>");
36+
37+
message.setFrom(new EmailAddress("[email protected]"));
38+
message.setReplyTo(new EmailAddress("[email protected]"));
39+
40+
message.getTo().add(new BulkRecipient("[email protected]"));
41+
message.getTo().add(new BulkRecipient("[email protected]", "Recipient #2"));
42+
message.getTo().add(new BulkRecipient("[email protected]"));
43+
message.getTo().add(new BulkRecipient("[email protected]", "Recipient #4"));
44+
45+
// create the client
46+
SocketLabsClient client = new SocketLabsClient(ExampleConfig.ServerId, ExampleConfig.ApiKey);
47+
48+
// send the message
49+
SendResponse response = client.send(message);
50+
51+
return response;
52+
}
53+
}

examples/src/main/java/examples/html/SimpleEmail.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<meta charset="utf-8" />
66
<title>Lorem Ipsum</title>
77
</head>
8-
<body>
8+
<body style="background-color: powderblue">
99
<div>
10-
<h1>Lorem Ipsum</h1>
10+
<h1 style ="color: white">Lorem Ipsum</h1>
1111
<h2>The standard Lorem Ipsum passage, used since the 1500s</h2>
1212
<p>
1313
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod

0 commit comments

Comments
 (0)