Rev 934 | Rev 936 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
29 | jmachado | 1 | package pt.estgp.estgweb.services.email; |
2 | |||
236 | jmachado | 3 | import jomm.utils.TemplateUtils; |
4 | import org.apache.log4j.Logger; |
||
5 | import pt.estgp.estgweb.Globals; |
||
929 | jmachado | 6 | import pt.estgp.estgweb.domain.*; |
7 | import pt.estgp.estgweb.domain.enums.LangEnum; |
||
8 | import pt.estgp.estgweb.services.expceptions.ServiceException; |
||
751 | jmachado | 9 | import pt.estgp.estgweb.utils.ConfigProperties; |
929 | jmachado | 10 | import pt.estgp.estgweb.utils.Email; |
358 | jmachado | 11 | import pt.estgp.estgweb.web.utils.DatesUtils; |
236 | jmachado | 12 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
13 | |||
929 | jmachado | 14 | import javax.mail.*; |
15 | import javax.mail.internet.InternetAddress; |
||
236 | jmachado | 16 | import javax.mail.internet.MimeMessage; |
872 | jmachado | 17 | import java.io.UnsupportedEncodingException; |
929 | jmachado | 18 | import java.text.MessageFormat; |
236 | jmachado | 19 | import java.util.ArrayList; |
929 | jmachado | 20 | import java.util.Date; |
29 | jmachado | 21 | import java.util.List; |
236 | jmachado | 22 | import java.util.Properties; |
29 | jmachado | 23 | |
24 | /** |
||
25 | * @author Jorge Machado |
||
26 | * @date 20/Mar/2008 |
||
27 | * @time 18:31:00 |
||
28 | * @see pt.estgp.estgweb.services.email |
||
29 | */ |
||
236 | jmachado | 30 | public class SendEmailService implements IService |
29 | jmachado | 31 | { |
236 | jmachado | 32 | private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(SendEmailService.class); |
33 | |||
34 | private static final 1.5.0/docs/api/java/lang/String.html">String gradeUnitTemplate = Globals.TEMPLATE_EMAIL_PATH + "/" + Globals.EMAIL_GRADE_UNIT_TEMPLATE; |
||
35 | |||
36 | public void sendEmail(Email email) throws ServiceException |
||
29 | jmachado | 37 | { |
236 | jmachado | 38 | try{ |
39 | |||
40 | // Set up properties for mail session |
||
41 | 1.5.0/docs/api/java/util/Properties.html">Properties props = 1.5.0/docs/api/java/lang/System.html">System.getProperties(); |
||
42 | props.put("mail.smtp.host", Globals.EMAIL_SERVER_HOST); |
||
929 | jmachado | 43 | final 1.5.0/docs/api/java/lang/String.html">String username = Globals.EMAIL_SERVER_USERNAME; |
44 | final 1.5.0/docs/api/java/lang/String.html">String password = Globals.EMAIL_SERVER_PASSWORD; |
||
45 | javax.mail.1.5.0/docs/api/java/net/Authenticator.html">Authenticator authenticator = null; |
||
46 | if(Globals.EMAIL_SERVER_SECURITY != null && Globals.EMAIL_SERVER_SECURITY.compareTo("TLS")==0) |
||
47 | { |
||
48 | props.put("mail.smtp.auth", "true"); |
||
49 | props.put("mail.smtp.starttls.enable", "true"); |
||
50 | props.put("mail.smtp.port", ""+ Globals.EMAIL_SERVER_SECURITY_TLS); |
||
51 | authenticator = new javax.mail.1.5.0/docs/api/java/net/Authenticator.html">Authenticator() { |
||
52 | protected 1.5.0/docs/api/java/net/PasswordAuthentication.html">PasswordAuthentication getPasswordAuthentication() { |
||
53 | return new 1.5.0/docs/api/java/net/PasswordAuthentication.html">PasswordAuthentication(username, password); |
||
54 | } |
||
55 | }; |
||
56 | } |
||
57 | else if(Globals.EMAIL_SERVER_SECURITY != null && Globals.EMAIL_SERVER_SECURITY.compareTo("SSL")==0) |
||
58 | { |
||
59 | props.put("mail.smtp.socketFactory.port", Globals.EMAIL_SERVER_SECURITY_SSL); |
||
60 | props.put("mail.smtp.socketFactory.class", |
||
61 | "javax.net.ssl.SSLSocketFactory"); |
||
62 | props.put("mail.smtp.auth", "true"); |
||
63 | props.put("mail.smtp.port", Globals.EMAIL_SERVER_SECURITY_SSL); |
||
64 | authenticator = new javax.mail.1.5.0/docs/api/java/net/Authenticator.html">Authenticator() { |
||
65 | protected 1.5.0/docs/api/java/net/PasswordAuthentication.html">PasswordAuthentication getPasswordAuthentication() { |
||
66 | return new 1.5.0/docs/api/java/net/PasswordAuthentication.html">PasswordAuthentication(username,password); |
||
67 | } |
||
68 | }; |
||
69 | } |
||
70 | else |
||
71 | { |
||
236 | jmachado | 72 | |
929 | jmachado | 73 | } |
74 | |||
75 | |||
76 | |||
77 | |||
78 | |||
79 | |||
236 | jmachado | 80 | // Get session |
930 | jmachado | 81 | Session session = Session.getDefaultInstance(props, authenticator); |
933 | jmachado | 82 | session.setDebug(true); |
83 | session.setDebugOut(1.5.0/docs/api/java/lang/System.html">System.out); |
||
236 | jmachado | 84 | |
85 | // Create message |
||
86 | MimeMessage message = new MimeMessage(session); |
||
87 | // Set the recipients of the message |
||
298 | jmachado | 88 | boolean valid = false; |
89 | for (1.5.0/docs/api/java/lang/String.html">String recipient : email.getRecipients()) |
||
90 | { |
||
91 | if(Email.validEmail(recipient)) |
||
92 | { |
||
93 | valid=true; |
||
419 | jmachado | 94 | message.addRecipient(email.getType(),new InternetAddress(recipient)); |
811 | jmachado | 95 | logger.info("Adding recipient to transport:"+recipient); |
298 | jmachado | 96 | } |
236 | jmachado | 97 | } |
298 | jmachado | 98 | if(valid) |
99 | { |
||
811 | jmachado | 100 | |
298 | jmachado | 101 | 1.5.0/docs/api/java/lang/String.html">String content = TemplateUtils.getOrLoadTemplate(Globals.TEMPLATE_EMAIL_PATH + "/" + email.getEmailTemplateName()); |
102 | // Format the mail message |
||
935 | jmachado | 103 | 1.5.0/docs/api/java/lang/String.html">String fullMessage = 1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.format(content, email.getArguments().toArray()) |
104 | + email.getFrom() != null && email.getFrom().length()>0 ? "Responda para " + email.getFrom() : "" |
||
105 | ; |
||
236 | jmachado | 106 | |
935 | jmachado | 107 | |
108 | |||
931 | jmachado | 109 | logger.info("FROM:" + email.getFrom() + " but using: " + Globals.SYSTEM_EMAIL_BOX); |
932 | jmachado | 110 | //if(email.getFromName() != null) |
872 | jmachado | 111 | try { |
934 | jmachado | 112 | message.setFrom(new InternetAddress(Globals.SYSTEM_EMAIL_BOX,Globals.SYSTEM_EMAIL_BOX)); |
872 | jmachado | 113 | } catch (1.5.0/docs/api/java/io/UnsupportedEncodingException.html">UnsupportedEncodingException e) { |
114 | logger.error(e,e); |
||
115 | message.setFrom(new InternetAddress(email.getFrom())); |
||
116 | } |
||
932 | jmachado | 117 | //else |
118 | // message.setFrom(new InternetAddress(Globals.SYSTEM_EMAIL_BOX)); |
||
935 | jmachado | 119 | message.setSubject(email.getSubject() + " - não responda para este endereço"); |
492 | jmachado | 120 | message.setText(fullMessage,"utf-8"); |
236 | jmachado | 121 | |
490 | jmachado | 122 | |
935 | jmachado | 123 | |
512 | jmachado | 124 | if(email.isHtml()) |
935 | jmachado | 125 | { |
512 | jmachado | 126 | message.setHeader("Content-Type","text/html; charset=\"utf-8\""); |
935 | jmachado | 127 | fullMessage+=" <br/> <br/> <h5> Mensagem Segura - enviada através da Google Apps Api através de baco 2015 </h5>"; |
128 | } |
||
512 | jmachado | 129 | else |
935 | jmachado | 130 | { |
512 | jmachado | 131 | message.setHeader("Content-Type","text/plain; charset=\"utf-8\""); |
935 | jmachado | 132 | fullMessage+=" \n\n Mensagem Segura - enviada através da Google Apps Api através de baco 2015"; |
133 | } |
||
490 | jmachado | 134 | message.setHeader("Content-Transfer-Encoding", "quoted-printable"); |
811 | jmachado | 135 | logger.info("Sending email to transport:"+fullMessage); |
492 | jmachado | 136 | |
811 | jmachado | 137 | |
933 | jmachado | 138 | |
298 | jmachado | 139 | Transport.send(message); |
140 | } |
||
236 | jmachado | 141 | } |
142 | catch(MessagingException e) |
||
143 | { |
||
144 | logger.error(e,e); |
||
145 | throw new ServiceException(e.toString()); |
||
146 | } |
||
29 | jmachado | 147 | } |
236 | jmachado | 148 | |
149 | public Email getSendUrlToFriendEmail(1.5.0/docs/api/java/lang/String.html">String url, 1.5.0/docs/api/java/lang/String.html">String from, LangEnum langEnum, List<String> recipients) |
||
150 | { |
||
151 | List<String> arguments = new ArrayList<String>(); |
||
152 | arguments.add(from); |
||
153 | arguments.add(url); |
||
154 | 1.5.0/docs/api/java/lang/String.html">String subjectTxt; |
||
155 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
156 | |||
157 | if(langEnum == LangEnum.PORTUGUESE) |
||
158 | { |
||
159 | template = Globals.EMAIL_SEND_URL_FRIEND_TEMPLATE_PT; |
||
237 | jmachado | 160 | subjectTxt = Globals.EMAIL_SEND_URL_FRIEND_SUBJECT_PT; |
236 | jmachado | 161 | } |
162 | else |
||
163 | { |
||
164 | template = Globals.EMAIL_SEND_URL_FRIEND_TEMPLATE_EN; |
||
237 | jmachado | 165 | subjectTxt = Globals.EMAIL_SEND_URL_FRIEND_SUBJECT_EN; |
236 | jmachado | 166 | } |
167 | |||
168 | 1.5.0/docs/api/java/lang/String.html">String subject = java.text.1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.format(subjectTxt,new 1.5.0/docs/api/java/lang/String.html">String[]{from}); |
||
169 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
170 | } |
||
171 | |||
172 | public boolean sendUrlToFriend(1.5.0/docs/api/java/lang/String.html">String url, 1.5.0/docs/api/java/lang/String.html">String from, LangEnum langEnum, List<String> recipients) |
||
173 | { |
||
174 | try |
||
175 | { |
||
176 | sendEmail(getSendUrlToFriendEmail(url,from,langEnum,recipients)); |
||
177 | return true; |
||
178 | } |
||
179 | catch (ServiceException e) |
||
180 | { |
||
181 | return false; |
||
182 | } |
||
183 | } |
||
184 | |||
237 | jmachado | 185 | public boolean sendCourseUnitAnnouncement(CourseUnitAnnouncement announcement, LangEnum langEnum, 1.5.0/docs/api/java/lang/String.html">String from, List<User> users) |
186 | { |
||
187 | try |
||
188 | { |
||
189 | sendEmail(getCourseUnitAnnouncementEmail(announcement,langEnum,from,users)); |
||
190 | return true; |
||
191 | } |
||
192 | catch (ServiceException e) |
||
193 | { |
||
194 | return false; |
||
195 | } |
||
196 | } |
||
236 | jmachado | 197 | |
512 | jmachado | 198 | public Email getMessageEmail(1.5.0/docs/api/java/lang/String.html">String from, 1.5.0/docs/api/java/lang/String.html">String subject,1.5.0/docs/api/java/lang/String.html">String text, LangEnum langEnum, 1.5.0/docs/api/java/lang/String.html">String target, List<User> users, User user) |
199 | { |
||
200 | // # 0 : From |
||
201 | // # 1 : Subject |
||
202 | // # 2 : Text |
||
203 | // # 3 : person |
||
204 | // # 4 : target |
||
205 | List<String> arguments = new ArrayList<String>(); |
||
206 | arguments.add(from); |
||
207 | arguments.add(subject); |
||
208 | arguments.add(text); |
||
209 | arguments.add(user.getName()); |
||
210 | arguments.add(target); |
||
211 | |||
212 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
213 | |||
214 | if(langEnum == LangEnum.PORTUGUESE) |
||
215 | { |
||
216 | template = Globals.EMAIL_MESSAGE_TEMPLATE_PT; |
||
217 | } |
||
218 | else |
||
219 | { |
||
220 | template = Globals.EMAIL_MESSAGE_TEMPLATE_EN; |
||
221 | } |
||
222 | |||
223 | List<String> recipients = new ArrayList<String>(); |
||
224 | for(User u: users) |
||
225 | { |
||
226 | if(Email.validEmail(u.getEmail())) |
||
227 | recipients.add(u.getEmail()); |
||
228 | if(Email.validEmail(u.getOutEmail())) |
||
229 | recipients.add(u.getOutEmail()); |
||
230 | } |
||
810 | jmachado | 231 | logger.info("subject: " + subject); |
232 | logger.info("user: " + user.getEmail()); |
||
233 | logger.info("template: " + template); |
||
234 | logger.info("arguments:"); |
||
235 | for(1.5.0/docs/api/java/lang/String.html">String arg: arguments) |
||
236 | logger.info(arg); |
||
237 | logger.info("recipients:"); |
||
238 | for(1.5.0/docs/api/java/lang/String.html">String rec: recipients) |
||
239 | logger.info(rec); |
||
240 | logger.info("arguments end"); |
||
872 | jmachado | 241 | Email email = new Email(subject ,recipients,user.getEmail(),template,arguments,Message.RecipientType.BCC); |
242 | email.setFromName(from + " (ESTG)"); |
||
243 | return email; |
||
512 | jmachado | 244 | } |
245 | |||
237 | jmachado | 246 | public Email getCourseUnitAnnouncementEmail(CourseUnitAnnouncement announcement, LangEnum langEnum, 1.5.0/docs/api/java/lang/String.html">String from, List<User> users) |
247 | { |
||
248 | List<String> arguments = new ArrayList<String>(); |
||
249 | arguments.add(announcement.getCourseUnit().getName()); |
||
250 | arguments.add(announcement.getTitle()); |
||
251 | arguments.add(announcement.getText()); |
||
252 | arguments.add(from); |
||
253 | |||
254 | 1.5.0/docs/api/java/lang/String.html">String subjectTxt; |
||
255 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
256 | |||
257 | if(langEnum == LangEnum.PORTUGUESE) |
||
258 | { |
||
259 | template = Globals.EMAIL_COURSEUNIT_ANNOUNCEMENT_TEMPLATE_PT; |
||
260 | subjectTxt = Globals.EMAIL_COURSEUNIT_ANNOUNCEMENT_SUBJECT_PT; |
||
261 | } |
||
262 | else |
||
263 | { |
||
264 | template = Globals.EMAIL_COURSEUNIT_ANNOUNCEMENT_TEMPLATE_EN; |
||
265 | subjectTxt = Globals.EMAIL_COURSEUNIT_ANNOUNCEMENT_SUBJECT_EN; |
||
266 | } |
||
267 | |||
268 | List<String> recipients = new ArrayList<String>(); |
||
269 | for(User u: users) |
||
270 | { |
||
298 | jmachado | 271 | if(Email.validEmail(u.getEmail())) |
272 | recipients.add(u.getEmail()); |
||
419 | jmachado | 273 | if(Email.validEmail(u.getOutEmail())) |
274 | recipients.add(u.getOutEmail()); |
||
237 | jmachado | 275 | } |
276 | |||
277 | 1.5.0/docs/api/java/lang/String.html">String subject = java.text.1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.format(subjectTxt,new 1.5.0/docs/api/java/lang/String.html">String[]{announcement.getCourseUnit().getNormalizedName(),announcement.getTitle()}); |
||
419 | jmachado | 278 | 1.5.0/docs/api/java/lang/String.html">String fromEmail = Globals.SYSTEM_EMAIL_BOX; |
279 | if(announcement.getOwner() != null && Email.validEmail(announcement.getOwner().getEmail())) |
||
280 | fromEmail = announcement.getOwner().getEmail(); |
||
281 | return new Email(subject ,recipients,fromEmail,template,arguments,Message.RecipientType.BCC); |
||
237 | jmachado | 282 | } |
283 | |||
363 | jmachado | 284 | public Email getCourseUnitBlogPostEmail(BlogPost post, LangEnum langEnum, 1.5.0/docs/api/java/lang/String.html">String from, List<User> users) |
285 | { |
||
286 | List<String> arguments = new ArrayList<String>(); |
||
287 | arguments.add(((CourseUnitBlog)post.getBlog()).getCourseUnit().getName()); |
||
288 | arguments.add(post.getTitle()); |
||
289 | arguments.add(post.getText()); |
||
290 | arguments.add(from); |
||
237 | jmachado | 291 | |
363 | jmachado | 292 | 1.5.0/docs/api/java/lang/String.html">String subjectTxt; |
293 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
294 | |||
295 | if(langEnum == LangEnum.PORTUGUESE) |
||
296 | { |
||
297 | template = Globals.EMAIL_COURSEUNIT_BLOGPOST_TEMPLATE_PT; |
||
298 | subjectTxt = Globals.EMAIL_COURSEUNIT_BLOGPOST_SUBJECT_PT; |
||
299 | } |
||
300 | else |
||
301 | { |
||
302 | template = Globals.EMAIL_COURSEUNIT_BLOGPOST_TEMPLATE_EN; |
||
303 | subjectTxt = Globals.EMAIL_COURSEUNIT_BLOGPOST_SUBJECT_EN; |
||
304 | } |
||
305 | |||
306 | List<String> recipients = new ArrayList<String>(); |
||
307 | for(User u: users) |
||
308 | { |
||
309 | if(Email.validEmail(u.getEmail())) |
||
310 | recipients.add(u.getEmail()); |
||
419 | jmachado | 311 | if(Email.validEmail(u.getOutEmail())) |
312 | recipients.add(u.getOutEmail()); |
||
363 | jmachado | 313 | } |
314 | |||
315 | 1.5.0/docs/api/java/lang/String.html">String subject = java.text.1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.format(subjectTxt,new 1.5.0/docs/api/java/lang/String.html">String[]{((CourseUnitBlog)post.getBlog()).getCourseUnit().getNormalizedName(),post.getTitle()}); |
||
419 | jmachado | 316 | 1.5.0/docs/api/java/lang/String.html">String fromEmail = Globals.SYSTEM_EMAIL_BOX; |
317 | if(post.getOwner() != null && Email.validEmail(post.getOwner().getEmail())) |
||
318 | fromEmail = post.getOwner().getEmail(); |
||
319 | return new Email(subject ,recipients, fromEmail, template,arguments,Message.RecipientType.BCC); |
||
363 | jmachado | 320 | } |
321 | |||
440 | jmachado | 322 | public Email getCourseUnitWorkEmail(CourseUnitAssignement assignement, LangEnum langEnum, UserSession userSession, List<User> users, boolean newWork) |
419 | jmachado | 323 | { |
324 | List<String> arguments = new ArrayList<String>(); |
||
325 | arguments.add(assignement.getCourseUnit().getName()); |
||
326 | arguments.add(assignement.getTitle()); |
||
327 | arguments.add(assignement.getDescription()); |
||
440 | jmachado | 328 | |
419 | jmachado | 329 | if(userSession != null && userSession.getName() != null) |
330 | arguments.add(userSession.getName()); |
||
331 | else |
||
332 | arguments.add("unknown"); |
||
363 | jmachado | 333 | |
440 | jmachado | 334 | arguments.add( DatesUtils.getStringFromDate(assignement.getDeliverDate())); |
492 | jmachado | 335 | |
419 | jmachado | 336 | 1.5.0/docs/api/java/lang/String.html">String subjectTxt; |
337 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
338 | |||
339 | if(langEnum == LangEnum.PORTUGUESE) |
||
340 | { |
||
440 | jmachado | 341 | if(newWork) |
342 | template = Globals.EMAIL_COURSEUNIT_WORK_TEMPLATE_PT; |
||
343 | else |
||
344 | template = Globals.EMAIL_COURSEUNIT_WORK_CHANGE_TEMPLATE_PT; |
||
419 | jmachado | 345 | subjectTxt = Globals.EMAIL_COURSEUNIT_WORK_SUBJECT_PT; |
346 | } |
||
347 | else |
||
348 | { |
||
440 | jmachado | 349 | if(newWork) |
350 | template = Globals.EMAIL_COURSEUNIT_WORK_TEMPLATE_EN; |
||
351 | else |
||
352 | template = Globals.EMAIL_COURSEUNIT_WORK_CHANGE_TEMPLATE_EN; |
||
419 | jmachado | 353 | subjectTxt = Globals.EMAIL_COURSEUNIT_WORK_SUBJECT_EN; |
354 | } |
||
355 | |||
356 | List<String> recipients = new ArrayList<String>(); |
||
357 | for(User u: users) |
||
358 | { |
||
359 | if(Email.validEmail(u.getEmail())) |
||
360 | recipients.add(u.getEmail()); |
||
361 | if(Email.validEmail(u.getOutEmail())) |
||
362 | recipients.add(u.getOutEmail()); |
||
363 | } |
||
364 | |||
365 | 1.5.0/docs/api/java/lang/String.html">String subject = java.text.1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.format(subjectTxt,new 1.5.0/docs/api/java/lang/String.html">String[]{assignement.getCourseUnit().getNormalizedName(),assignement.getTitle()}); |
||
366 | |||
367 | 1.5.0/docs/api/java/lang/String.html">String fromEmail = Globals.SYSTEM_EMAIL_BOX; |
||
368 | if(userSession!= null && userSession.getUser() != null && Email.validEmail(userSession.getUser().getEmail())) |
||
369 | fromEmail = userSession.getUser().getEmail(); |
||
370 | return new Email(subject ,recipients,fromEmail,template,arguments,Message.RecipientType.BCC); |
||
371 | } |
||
372 | |||
373 | |||
374 | |||
236 | jmachado | 375 | public Email getNewGradesEmail(List<String[]> grades, LangEnum langEnum, 1.5.0/docs/api/java/lang/String.html">String studentEmail, 1.5.0/docs/api/java/lang/String.html">String studentName) |
376 | { |
||
377 | List<String> arguments = new ArrayList<String>(); |
||
378 | |||
379 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
380 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
381 | |||
382 | if(langEnum == LangEnum.PORTUGUESE) |
||
383 | { |
||
384 | template = Globals.EMAIL_NEW_GRADES_TEMPLATE_PT; |
||
237 | jmachado | 385 | subject = Globals.EMAIL_NEW_GRADES_SUBJECT_PT; |
236 | jmachado | 386 | } |
387 | else |
||
388 | { |
||
389 | template = Globals.EMAIL_NEW_GRADES_TEMPLATE_EN; |
||
237 | jmachado | 390 | subject = Globals.EMAIL_NEW_GRADES_SUBJECT_EN; |
236 | jmachado | 391 | } |
392 | |||
393 | 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder gradesBuilder = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder(); |
||
394 | for(1.5.0/docs/api/java/lang/String.html">String[] grade: grades) |
||
395 | { |
||
396 | 1.5.0/docs/api/java/lang/String.html">String gradeTxt = TemplateUtils.formatMessageTemplate(gradeUnitTemplate,grade); |
||
397 | gradesBuilder.append(gradeTxt); |
||
398 | } |
||
399 | |||
400 | arguments.add(studentName); |
||
401 | arguments.add(gradesBuilder.toString()); |
||
402 | |||
403 | List<String> recipients = new ArrayList<String>(); |
||
404 | recipients.add(studentEmail); |
||
405 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
406 | } |
||
407 | |||
358 | jmachado | 408 | public Email getSummaryEmail(List<String> emails, CourseUnitSummary cUS, CourseUnit c, LangEnum langEnum) |
409 | { |
||
410 | List<String> arguments = new ArrayList<String>(); |
||
411 | |||
412 | 1.5.0/docs/api/java/lang/String.html">String data = DatesUtils.getStringFromDate(cUS.getDataAula()); |
||
413 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
414 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
415 | |||
416 | if(langEnum == LangEnum.PORTUGUESE) |
||
417 | { |
||
418 | template = Globals.EMAIL_SUMMARY_TEMPLATE_PT; |
||
419 | subject = Globals.EMAIL_SUMMARY_SUBJECT_PT; |
||
420 | } |
||
421 | else |
||
422 | { |
||
423 | template = Globals.EMAIL_SUMMARY_TEMPLATE_EN; |
||
424 | subject = Globals.EMAIL_SUMMARY_SUBJECT_EN; |
||
425 | } |
||
426 | subject = TemplateUtils.formatMessageTemplate(subject,new 1.5.0/docs/api/java/lang/String.html">String[]{c.getName()}); |
||
427 | |||
428 | arguments.add(c.getName()); |
||
429 | arguments.add(""+cUS.getNumeroAula()); |
||
430 | arguments.add(data); |
||
431 | arguments.add(cUS.getTitulo()); |
||
432 | arguments.add(cUS.getDescricao()); |
||
433 | |||
434 | List<String> recipients = new ArrayList<String>(); |
||
435 | for(1.5.0/docs/api/java/lang/String.html">String email:emails) |
||
436 | recipients.add(email); |
||
437 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
438 | } |
||
439 | |||
751 | jmachado | 440 | public Email getUnidadeEdicaoEmail(List<String> emails, CourseUnit c, LangEnum langEnum) |
441 | { |
||
442 | List<String> arguments = new ArrayList<String>(); |
||
443 | |||
444 | |||
445 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
446 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
447 | |||
448 | if(langEnum == LangEnum.PORTUGUESE) |
||
449 | { |
||
450 | template = Globals.EMAIL_UNDADE_EDICAO_TEMPLATE_PT; |
||
451 | subject = Globals.EMAIL_UNDADE_EDICAO_SUBJECT_PT; |
||
452 | } |
||
453 | else |
||
454 | { |
||
455 | template = Globals.EMAIL_UNDADE_EDICAO_TEMPLATE_EN; |
||
456 | subject = Globals.EMAIL_UNDADE_EDICAO_SUBJECT_EN; |
||
457 | } |
||
458 | subject = 1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.format(ConfigProperties.getProperty(subject),new 1.5.0/docs/api/java/lang/String.html">String[]{c.getName()}); |
||
459 | |||
460 | arguments.add(c.getName()); |
||
461 | |||
462 | List<String> recipients = new ArrayList<String>(); |
||
463 | for(1.5.0/docs/api/java/lang/String.html">String email:emails) |
||
464 | recipients.add(email); |
||
465 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
466 | } |
||
467 | |||
468 | public Email getUnidadeValidadaEmail(List<String> emails, CourseUnit c, LangEnum langEnum) |
||
469 | { |
||
470 | List<String> arguments = new ArrayList<String>(); |
||
471 | |||
472 | |||
473 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
474 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
475 | |||
476 | if(langEnum == LangEnum.PORTUGUESE) |
||
477 | { |
||
478 | template = Globals.EMAIL_UNDADE_VALIDADA_TEMPLATE_PT; |
||
479 | subject = Globals.EMAIL_UNDADE_VALIDADA_SUBJECT_PT; |
||
480 | } |
||
481 | else |
||
482 | { |
||
483 | template = Globals.EMAIL_UNDADE_VALIDADA_TEMPLATE_EN; |
||
484 | subject = Globals.EMAIL_UNDADE_VALIDADA_SUBJECT_EN; |
||
485 | } |
||
486 | subject = 1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.format(ConfigProperties.getProperty(subject),new 1.5.0/docs/api/java/lang/String.html">String[]{c.getName()}); |
||
487 | |||
488 | arguments.add(c.getName()); |
||
489 | |||
490 | List<String> recipients = new ArrayList<String>(); |
||
491 | for(1.5.0/docs/api/java/lang/String.html">String email:emails) |
||
492 | recipients.add(email); |
||
493 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
494 | } |
||
495 | |||
496 | public Email getUnidadeEditadaEmail(List<String> emails, CourseUnit c, LangEnum langEnum) |
||
497 | { |
||
498 | List<String> arguments = new ArrayList<String>(); |
||
499 | |||
500 | |||
501 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
502 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
503 | |||
504 | if(langEnum == LangEnum.PORTUGUESE) |
||
505 | { |
||
506 | template = Globals.EMAIL_UNDADE_EDITADA_TEMPLATE_PT; |
||
507 | subject = Globals.EMAIL_UNDADE_EDITADA_SUBJECT_PT; |
||
508 | } |
||
509 | else |
||
510 | { |
||
511 | template = Globals.EMAIL_UNDADE_EDITADA_TEMPLATE_EN; |
||
512 | subject = Globals.EMAIL_UNDADE_EDITADA_SUBJECT_EN; |
||
513 | } |
||
514 | subject = 1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.format(ConfigProperties.getProperty(subject),new 1.5.0/docs/api/java/lang/String.html">String[]{c.getName()}); |
||
515 | |||
516 | arguments.add(c.getCourseName()); |
||
517 | arguments.add(c.getName()); |
||
518 | |||
519 | List<String> recipients = new ArrayList<String>(); |
||
520 | for(1.5.0/docs/api/java/lang/String.html">String email:emails) |
||
521 | recipients.add(email); |
||
522 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
523 | } |
||
524 | |||
236 | jmachado | 525 | public boolean sendNewGrades(List<String[]> grades, LangEnum langEnum, 1.5.0/docs/api/java/lang/String.html">String studentEmail, 1.5.0/docs/api/java/lang/String.html">String studentName) |
526 | { |
||
527 | try |
||
528 | { |
||
529 | sendEmail(getNewGradesEmail(grades,langEnum,studentEmail,studentName)); |
||
530 | return true; |
||
531 | } |
||
532 | catch (ServiceException e) |
||
533 | { |
||
534 | return false; |
||
535 | } |
||
536 | |||
537 | } |
||
538 | |||
539 | public static void main(1.5.0/docs/api/java/lang/String.html">String [] args) |
||
540 | { |
||
440 | jmachado | 541 | 1.5.0/docs/api/java/lang/System.html">System.out.println( DatesUtils.getStringFromDate(new 5+0%2Fdocs%2Fapi+Date">Date())); |
542 | // List<String[]> grades = new ArrayList<String[]>(); |
||
543 | // grades.add(new String[]{"Teste","3"}); |
||
544 | // grades.add(new String[]{"Teste2","4"}); |
||
545 | // new SendEmailService().sendNewGrades(grades,LangEnum.PORTUGUESE,"jmachado@estgp.pt","jorge Machado"); |
||
236 | jmachado | 546 | } |
547 | |||
29 | jmachado | 548 | } |