Revision 54676
Added by Konstantina Galouni about 5 years ago
EmailController.java | ||
---|---|---|
11 | 11 |
import org.springframework.web.bind.annotation.*; |
12 | 12 |
|
13 | 13 |
import java.util.ArrayList; |
14 |
import java.util.HashMap; |
|
14 | 15 |
import java.util.List; |
16 |
import java.util.Map; |
|
15 | 17 |
|
16 | 18 |
@RestController |
17 | 19 |
@CrossOrigin(origins = "*") |
... | ... | |
30 | 32 |
//notify about new subscribers - check manager option |
31 | 33 |
//notify for claims - check manager option --> claim API |
32 | 34 |
@RequestMapping(value = "/sendMail", method = RequestMethod.POST) |
33 |
public Integer sendEmail(@RequestBody Email email ) { |
|
34 |
int send = 0; |
|
35 |
public Map<String, ArrayList<String>> sendEmail(@RequestBody Email email ) { |
|
36 |
String successString = "success"; |
|
37 |
String failureString = "failure"; |
|
38 |
Map<String, ArrayList<String>> mailResults = new HashMap<>(); |
|
39 |
|
|
35 | 40 |
for(String userMail:email.getRecipients()){ |
36 | 41 |
ArrayList<String> sendTo = new ArrayList<>(); |
37 | 42 |
sendTo.add(userMail); |
38 | 43 |
boolean success =emailSender.send(sendTo,email.getSubject(),email.getBody(), true); |
39 | 44 |
if(success){ |
40 |
send ++; |
|
45 |
if(!mailResults.containsKey(successString)) { |
|
46 |
mailResults.put(successString, new ArrayList<>()); |
|
47 |
} |
|
48 |
mailResults.get(successString).add(userMail); |
|
49 |
} else { |
|
50 |
if(!mailResults.containsKey(failureString)) { |
|
51 |
mailResults.put(failureString, new ArrayList<>()); |
|
52 |
} |
|
53 |
mailResults.get(failureString).add(userMail); |
|
41 | 54 |
} |
42 | 55 |
} |
43 |
return send;
|
|
56 |
return mailResults;
|
|
44 | 57 |
|
45 | 58 |
} |
46 | 59 |
|
Also available in: Unified diff
1. emailSender/EmailSender.java: enable property 'starttls' for mail (necessary when sending mail to mailing list address).
2. controllers/EmailController.java: 'sendEmail()' function returns success and failure lists for all emails to be sent.
3. resources/admintools.properties: change 'UserInfoUrl' property from 'mpagasas' to 'scoobydoo'.