forked from sendgrid/sendgrid-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCampaign.java
More file actions
46 lines (41 loc) · 1.17 KB
/
Campaign.java
File metadata and controls
46 lines (41 loc) · 1.17 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
package com.sendgrid;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
/**
* A class allowing multiple emails to be sent simultaneously.
*/
public class Campaign {
private final List<Mail> mail = new ArrayList<>();
/**
* Get the mail objcts in this campaign.
* @return the list of mail objects.
*/
public List<Mail> getMail() {
return this.mail;
}
/**
* Add a mail object to this campaign.
* @param mail a mail to add to the campaign.
* @return this campaign.
*/
public Campaign mail(Mail mail) {
this.mail.add(mail);
return this;
}
/**
* Send all the email in this campaign.
* @param sg a Sendgrid object.
* @return the list of responses from sending the mail.
* @throws IOException in the event of a network error. Note that
* if any messages throws an error, the remaining members of the
* campaign will not be sent.
*/
public List<Response> send(SendGrid sg) throws IOException {
List<Response> ret = new ArrayList<>();
for(Mail m: this.mail) {
ret.add(m.send(sg));
}
return ret;
}
}