Revision 54676
Added by Konstantina Galouni over 4 years ago
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/controllers/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 |
|
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/emailSender/EmailSender.java | ||
---|---|---|
43 | 43 |
properties.setProperty("mail.smtp.host", host); |
44 | 44 |
properties.put("mail.smtp.port", port); |
45 | 45 |
properties.put("mail.smtp.auth", auth); //enable authentication |
46 |
properties.put("mail.smtp.starttls.enable", "true"); |
|
46 | 47 |
logger.debug("Try to connect to mail sender with "+username); |
47 | 48 |
Session session = Session.getInstance(properties, |
48 | 49 |
new javax.mail.Authenticator() { |
modules/uoa-admin-tools/src/main/resources/admintools.properties | ||
---|---|---|
1 | 1 |
#dev |
2 |
admintool.userInfoUrl = http://mpagasas.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/api/users/getUserInfo?accessToken=
|
|
2 |
admintool.userInfoUrl = http://scoobydoo.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/api/users/getUserInfo?accessToken=
|
|
3 | 3 |
admintool.originServer = .di.uoa.gr |
4 | 4 |
admintool.host = smtp.gmail.com |
5 | 5 |
admintool.port = 587 |
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'.