-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSendWithUsExample.java
73 lines (60 loc) · 2.55 KB
/
SendWithUsExample.java
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
import java.util.HashMap;
import java.util.Map;
import com.sendwithus.SendWithUs;
import com.sendwithus.exception.SendWithUsException;
import com.sendwithus.model.DeactivatedDrips;
import com.sendwithus.model.Email;
import com.sendwithus.model.SendReceipt;
public class SendWithUsExample {
public static final String SENDWITHUS_API_KEY = "YOUR-API-KEY-HERE";
public static final String EMAIL_ID_WELCOME_EMAIL = "YOUR-EMAIL-ID-HERE";
public static void main(String[] args) {
SendWithUs sendwithusAPI = new SendWithUs(SENDWITHUS_API_KEY);
// Print list of available emails
try {
Email[] emails = sendwithusAPI.templates();
for (int i = 0; i < emails.length; i++) {
System.out.println(emails[i].toString());
}
} catch (SendWithUsException e) {
System.out.println(e.toString());
}
// Send Welcome Email
Map<String, Object> recipientMap = new HashMap<String, Object>();
recipientMap.put("name", "Brad"); // optional
recipientMap.put("address", "[email protected]");
// sender is optional
Map<String, Object> senderMap = new HashMap<String, Object>();
senderMap.put("name", "Company"); // optional
senderMap.put("address", "[email protected]");
senderMap.put("reply_to", "[email protected]"); // optional
// email data in to inject in the email template
Map<String, Object> emailDataMap = new HashMap<String, Object>();
emailDataMap.put("first_name", "Brad");
emailDataMap.put("link", "http://sendwithus.com/some_link");
// Example sending a simple email
try {
SendReceipt sendReceipt = sendwithusAPI.send(
EMAIL_ID_WELCOME_EMAIL,
recipientMap,
senderMap,
emailDataMap
);
System.out.println(sendReceipt);
} catch (SendWithUsException e) {
System.out.println(e.toString());
}
// Example sending the same simple email using the new SendWithUsSendRequest class
try {
SendWithUsSendRequest request = new SendWithUsSendRequest()
.setEmailId(EMAIL_ID_WELCOME_EMAIL)
.setRecipient(recipientMap)
.setSender(senderMap)
.setEmailData(emailDataMap);
SendReceipt sendReceipt = sendwithusAPI.send(request);
System.out.println(sendReceipt);
} catch (SendWithUsException e) {
System.out.println(e.toString());
}
}
}