Rev 932 | Rev 934 | 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 |
||
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()); |
||
236 | jmachado | 104 | |
931 | jmachado | 105 | logger.info("FROM:" + email.getFrom() + " but using: " + Globals.SYSTEM_EMAIL_BOX); |
932 | jmachado | 106 | //if(email.getFromName() != null) |
872 | jmachado | 107 | try { |
932 | jmachado | 108 | message.setFrom(new InternetAddress(Globals.SYSTEM_EMAIL_BOX,"Baco Baco")); |
872 | jmachado | 109 | } catch (1.5.0/docs/api/java/io/UnsupportedEncodingException.html">UnsupportedEncodingException e) { |
110 | logger.error(e,e); |
||
111 | message.setFrom(new InternetAddress(email.getFrom())); |
||
112 | } |
||
932 | jmachado | 113 | //else |
114 | // message.setFrom(new InternetAddress(Globals.SYSTEM_EMAIL_BOX)); |
||
931 | jmachado | 115 | message.setSubject(email.getSubject() + " - do not reply to this email"); |
492 | jmachado | 116 | message.setText(fullMessage,"utf-8"); |
236 | jmachado | 117 | |
490 | jmachado | 118 | |
512 | jmachado | 119 | if(email.isHtml()) |
120 | message.setHeader("Content-Type","text/html; charset=\"utf-8\""); |
||
121 | else |
||
122 | message.setHeader("Content-Type","text/plain; charset=\"utf-8\""); |
||
490 | jmachado | 123 | message.setHeader("Content-Transfer-Encoding", "quoted-printable"); |
811 | jmachado | 124 | logger.info("Sending email to transport:"+fullMessage); |
492 | jmachado | 125 | |
811 | jmachado | 126 | |
933 | jmachado | 127 | |
298 | jmachado | 128 | Transport.send(message); |
129 | } |
||
236 | jmachado | 130 | } |
131 | catch(MessagingException e) |
||
132 | { |
||
133 | logger.error(e,e); |
||
134 | throw new ServiceException(e.toString()); |
||
135 | } |
||
29 | jmachado | 136 | } |
236 | jmachado | 137 | |
138 | 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) |
||
139 | { |
||
140 | List<String> arguments = new ArrayList<String>(); |
||
141 | arguments.add(from); |
||
142 | arguments.add(url); |
||
143 | 1.5.0/docs/api/java/lang/String.html">String subjectTxt; |
||
144 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
145 | |||
146 | if(langEnum == LangEnum.PORTUGUESE) |
||
147 | { |
||
148 | template = Globals.EMAIL_SEND_URL_FRIEND_TEMPLATE_PT; |
||
237 | jmachado | 149 | subjectTxt = Globals.EMAIL_SEND_URL_FRIEND_SUBJECT_PT; |
236 | jmachado | 150 | } |
151 | else |
||
152 | { |
||
153 | template = Globals.EMAIL_SEND_URL_FRIEND_TEMPLATE_EN; |
||
237 | jmachado | 154 | subjectTxt = Globals.EMAIL_SEND_URL_FRIEND_SUBJECT_EN; |
236 | jmachado | 155 | } |
156 | |||
157 | 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}); |
||
158 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
159 | } |
||
160 | |||
161 | 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) |
||
162 | { |
||
163 | try |
||
164 | { |
||
165 | sendEmail(getSendUrlToFriendEmail(url,from,langEnum,recipients)); |
||
166 | return true; |
||
167 | } |
||
168 | catch (ServiceException e) |
||
169 | { |
||
170 | return false; |
||
171 | } |
||
172 | } |
||
173 | |||
237 | jmachado | 174 | public boolean sendCourseUnitAnnouncement(CourseUnitAnnouncement announcement, LangEnum langEnum, 1.5.0/docs/api/java/lang/String.html">String from, List<User> users) |
175 | { |
||
176 | try |
||
177 | { |
||
178 | sendEmail(getCourseUnitAnnouncementEmail(announcement,langEnum,from,users)); |
||
179 | return true; |
||
180 | } |
||
181 | catch (ServiceException e) |
||
182 | { |
||
183 | return false; |
||
184 | } |
||
185 | } |
||
236 | jmachado | 186 | |
512 | jmachado | 187 | 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) |
188 | { |
||
189 | // # 0 : From |
||
190 | // # 1 : Subject |
||
191 | // # 2 : Text |
||
192 | // # 3 : person |
||
193 | // # 4 : target |
||
194 | List<String> arguments = new ArrayList<String>(); |
||
195 | arguments.add(from); |
||
196 | arguments.add(subject); |
||
197 | arguments.add(text); |
||
198 | arguments.add(user.getName()); |
||
199 | arguments.add(target); |
||
200 | |||
201 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
202 | |||
203 | if(langEnum == LangEnum.PORTUGUESE) |
||
204 | { |
||
205 | template = Globals.EMAIL_MESSAGE_TEMPLATE_PT; |
||
206 | } |
||
207 | else |
||
208 | { |
||
209 | template = Globals.EMAIL_MESSAGE_TEMPLATE_EN; |
||
210 | } |
||
211 | |||
212 | List<String> recipients = new ArrayList<String>(); |
||
213 | for(User u: users) |
||
214 | { |
||
215 | if(Email.validEmail(u.getEmail())) |
||
216 | recipients.add(u.getEmail()); |
||
217 | if(Email.validEmail(u.getOutEmail())) |
||
218 | recipients.add(u.getOutEmail()); |
||
219 | } |
||
810 | jmachado | 220 | logger.info("subject: " + subject); |
221 | logger.info("user: " + user.getEmail()); |
||
222 | logger.info("template: " + template); |
||
223 | logger.info("arguments:"); |
||
224 | for(1.5.0/docs/api/java/lang/String.html">String arg: arguments) |
||
225 | logger.info(arg); |
||
226 | logger.info("recipients:"); |
||
227 | for(1.5.0/docs/api/java/lang/String.html">String rec: recipients) |
||
228 | logger.info(rec); |
||
229 | logger.info("arguments end"); |
||
872 | jmachado | 230 | Email email = new Email(subject ,recipients,user.getEmail(),template,arguments,Message.RecipientType.BCC); |
231 | email.setFromName(from + " (ESTG)"); |
||
232 | return email; |
||
512 | jmachado | 233 | } |
234 | |||
237 | jmachado | 235 | public Email getCourseUnitAnnouncementEmail(CourseUnitAnnouncement announcement, LangEnum langEnum, 1.5.0/docs/api/java/lang/String.html">String from, List<User> users) |
236 | { |
||
237 | List<String> arguments = new ArrayList<String>(); |
||
238 | arguments.add(announcement.getCourseUnit().getName()); |
||
239 | arguments.add(announcement.getTitle()); |
||
240 | arguments.add(announcement.getText()); |
||
241 | arguments.add(from); |
||
242 | |||
243 | 1.5.0/docs/api/java/lang/String.html">String subjectTxt; |
||
244 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
245 | |||
246 | if(langEnum == LangEnum.PORTUGUESE) |
||
247 | { |
||
248 | template = Globals.EMAIL_COURSEUNIT_ANNOUNCEMENT_TEMPLATE_PT; |
||
249 | subjectTxt = Globals.EMAIL_COURSEUNIT_ANNOUNCEMENT_SUBJECT_PT; |
||
250 | } |
||
251 | else |
||
252 | { |
||
253 | template = Globals.EMAIL_COURSEUNIT_ANNOUNCEMENT_TEMPLATE_EN; |
||
254 | subjectTxt = Globals.EMAIL_COURSEUNIT_ANNOUNCEMENT_SUBJECT_EN; |
||
255 | } |
||
256 | |||
257 | List<String> recipients = new ArrayList<String>(); |
||
258 | for(User u: users) |
||
259 | { |
||
298 | jmachado | 260 | if(Email.validEmail(u.getEmail())) |
261 | recipients.add(u.getEmail()); |
||
419 | jmachado | 262 | if(Email.validEmail(u.getOutEmail())) |
263 | recipients.add(u.getOutEmail()); |
||
237 | jmachado | 264 | } |
265 | |||
266 | 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 | 267 | 1.5.0/docs/api/java/lang/String.html">String fromEmail = Globals.SYSTEM_EMAIL_BOX; |
268 | if(announcement.getOwner() != null && Email.validEmail(announcement.getOwner().getEmail())) |
||
269 | fromEmail = announcement.getOwner().getEmail(); |
||
270 | return new Email(subject ,recipients,fromEmail,template,arguments,Message.RecipientType.BCC); |
||
237 | jmachado | 271 | } |
272 | |||
363 | jmachado | 273 | public Email getCourseUnitBlogPostEmail(BlogPost post, LangEnum langEnum, 1.5.0/docs/api/java/lang/String.html">String from, List<User> users) |
274 | { |
||
275 | List<String> arguments = new ArrayList<String>(); |
||
276 | arguments.add(((CourseUnitBlog)post.getBlog()).getCourseUnit().getName()); |
||
277 | arguments.add(post.getTitle()); |
||
278 | arguments.add(post.getText()); |
||
279 | arguments.add(from); |
||
237 | jmachado | 280 | |
363 | jmachado | 281 | 1.5.0/docs/api/java/lang/String.html">String subjectTxt; |
282 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
283 | |||
284 | if(langEnum == LangEnum.PORTUGUESE) |
||
285 | { |
||
286 | template = Globals.EMAIL_COURSEUNIT_BLOGPOST_TEMPLATE_PT; |
||
287 | subjectTxt = Globals.EMAIL_COURSEUNIT_BLOGPOST_SUBJECT_PT; |
||
288 | } |
||
289 | else |
||
290 | { |
||
291 | template = Globals.EMAIL_COURSEUNIT_BLOGPOST_TEMPLATE_EN; |
||
292 | subjectTxt = Globals.EMAIL_COURSEUNIT_BLOGPOST_SUBJECT_EN; |
||
293 | } |
||
294 | |||
295 | List<String> recipients = new ArrayList<String>(); |
||
296 | for(User u: users) |
||
297 | { |
||
298 | if(Email.validEmail(u.getEmail())) |
||
299 | recipients.add(u.getEmail()); |
||
419 | jmachado | 300 | if(Email.validEmail(u.getOutEmail())) |
301 | recipients.add(u.getOutEmail()); |
||
363 | jmachado | 302 | } |
303 | |||
304 | 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 | 305 | 1.5.0/docs/api/java/lang/String.html">String fromEmail = Globals.SYSTEM_EMAIL_BOX; |
306 | if(post.getOwner() != null && Email.validEmail(post.getOwner().getEmail())) |
||
307 | fromEmail = post.getOwner().getEmail(); |
||
308 | return new Email(subject ,recipients, fromEmail, template,arguments,Message.RecipientType.BCC); |
||
363 | jmachado | 309 | } |
310 | |||
440 | jmachado | 311 | public Email getCourseUnitWorkEmail(CourseUnitAssignement assignement, LangEnum langEnum, UserSession userSession, List<User> users, boolean newWork) |
419 | jmachado | 312 | { |
313 | List<String> arguments = new ArrayList<String>(); |
||
314 | arguments.add(assignement.getCourseUnit().getName()); |
||
315 | arguments.add(assignement.getTitle()); |
||
316 | arguments.add(assignement.getDescription()); |
||
440 | jmachado | 317 | |
419 | jmachado | 318 | if(userSession != null && userSession.getName() != null) |
319 | arguments.add(userSession.getName()); |
||
320 | else |
||
321 | arguments.add("unknown"); |
||
363 | jmachado | 322 | |
440 | jmachado | 323 | arguments.add( DatesUtils.getStringFromDate(assignement.getDeliverDate())); |
492 | jmachado | 324 | |
419 | jmachado | 325 | 1.5.0/docs/api/java/lang/String.html">String subjectTxt; |
326 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
327 | |||
328 | if(langEnum == LangEnum.PORTUGUESE) |
||
329 | { |
||
440 | jmachado | 330 | if(newWork) |
331 | template = Globals.EMAIL_COURSEUNIT_WORK_TEMPLATE_PT; |
||
332 | else |
||
333 | template = Globals.EMAIL_COURSEUNIT_WORK_CHANGE_TEMPLATE_PT; |
||
419 | jmachado | 334 | subjectTxt = Globals.EMAIL_COURSEUNIT_WORK_SUBJECT_PT; |
335 | } |
||
336 | else |
||
337 | { |
||
440 | jmachado | 338 | if(newWork) |
339 | template = Globals.EMAIL_COURSEUNIT_WORK_TEMPLATE_EN; |
||
340 | else |
||
341 | template = Globals.EMAIL_COURSEUNIT_WORK_CHANGE_TEMPLATE_EN; |
||
419 | jmachado | 342 | subjectTxt = Globals.EMAIL_COURSEUNIT_WORK_SUBJECT_EN; |
343 | } |
||
344 | |||
345 | List<String> recipients = new ArrayList<String>(); |
||
346 | for(User u: users) |
||
347 | { |
||
348 | if(Email.validEmail(u.getEmail())) |
||
349 | recipients.add(u.getEmail()); |
||
350 | if(Email.validEmail(u.getOutEmail())) |
||
351 | recipients.add(u.getOutEmail()); |
||
352 | } |
||
353 | |||
354 | 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()}); |
||
355 | |||
356 | 1.5.0/docs/api/java/lang/String.html">String fromEmail = Globals.SYSTEM_EMAIL_BOX; |
||
357 | if(userSession!= null && userSession.getUser() != null && Email.validEmail(userSession.getUser().getEmail())) |
||
358 | fromEmail = userSession.getUser().getEmail(); |
||
359 | return new Email(subject ,recipients,fromEmail,template,arguments,Message.RecipientType.BCC); |
||
360 | } |
||
361 | |||
362 | |||
363 | |||
236 | jmachado | 364 | 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) |
365 | { |
||
366 | List<String> arguments = new ArrayList<String>(); |
||
367 | |||
368 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
369 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
370 | |||
371 | if(langEnum == LangEnum.PORTUGUESE) |
||
372 | { |
||
373 | template = Globals.EMAIL_NEW_GRADES_TEMPLATE_PT; |
||
237 | jmachado | 374 | subject = Globals.EMAIL_NEW_GRADES_SUBJECT_PT; |
236 | jmachado | 375 | } |
376 | else |
||
377 | { |
||
378 | template = Globals.EMAIL_NEW_GRADES_TEMPLATE_EN; |
||
237 | jmachado | 379 | subject = Globals.EMAIL_NEW_GRADES_SUBJECT_EN; |
236 | jmachado | 380 | } |
381 | |||
382 | 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder gradesBuilder = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder(); |
||
383 | for(1.5.0/docs/api/java/lang/String.html">String[] grade: grades) |
||
384 | { |
||
385 | 1.5.0/docs/api/java/lang/String.html">String gradeTxt = TemplateUtils.formatMessageTemplate(gradeUnitTemplate,grade); |
||
386 | gradesBuilder.append(gradeTxt); |
||
387 | } |
||
388 | |||
389 | arguments.add(studentName); |
||
390 | arguments.add(gradesBuilder.toString()); |
||
391 | |||
392 | List<String> recipients = new ArrayList<String>(); |
||
393 | recipients.add(studentEmail); |
||
394 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
395 | } |
||
396 | |||
358 | jmachado | 397 | public Email getSummaryEmail(List<String> emails, CourseUnitSummary cUS, CourseUnit c, LangEnum langEnum) |
398 | { |
||
399 | List<String> arguments = new ArrayList<String>(); |
||
400 | |||
401 | 1.5.0/docs/api/java/lang/String.html">String data = DatesUtils.getStringFromDate(cUS.getDataAula()); |
||
402 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
403 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
404 | |||
405 | if(langEnum == LangEnum.PORTUGUESE) |
||
406 | { |
||
407 | template = Globals.EMAIL_SUMMARY_TEMPLATE_PT; |
||
408 | subject = Globals.EMAIL_SUMMARY_SUBJECT_PT; |
||
409 | } |
||
410 | else |
||
411 | { |
||
412 | template = Globals.EMAIL_SUMMARY_TEMPLATE_EN; |
||
413 | subject = Globals.EMAIL_SUMMARY_SUBJECT_EN; |
||
414 | } |
||
415 | subject = TemplateUtils.formatMessageTemplate(subject,new 1.5.0/docs/api/java/lang/String.html">String[]{c.getName()}); |
||
416 | |||
417 | arguments.add(c.getName()); |
||
418 | arguments.add(""+cUS.getNumeroAula()); |
||
419 | arguments.add(data); |
||
420 | arguments.add(cUS.getTitulo()); |
||
421 | arguments.add(cUS.getDescricao()); |
||
422 | |||
423 | List<String> recipients = new ArrayList<String>(); |
||
424 | for(1.5.0/docs/api/java/lang/String.html">String email:emails) |
||
425 | recipients.add(email); |
||
426 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
427 | } |
||
428 | |||
751 | jmachado | 429 | public Email getUnidadeEdicaoEmail(List<String> emails, CourseUnit c, LangEnum langEnum) |
430 | { |
||
431 | List<String> arguments = new ArrayList<String>(); |
||
432 | |||
433 | |||
434 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
435 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
436 | |||
437 | if(langEnum == LangEnum.PORTUGUESE) |
||
438 | { |
||
439 | template = Globals.EMAIL_UNDADE_EDICAO_TEMPLATE_PT; |
||
440 | subject = Globals.EMAIL_UNDADE_EDICAO_SUBJECT_PT; |
||
441 | } |
||
442 | else |
||
443 | { |
||
444 | template = Globals.EMAIL_UNDADE_EDICAO_TEMPLATE_EN; |
||
445 | subject = Globals.EMAIL_UNDADE_EDICAO_SUBJECT_EN; |
||
446 | } |
||
447 | 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()}); |
||
448 | |||
449 | arguments.add(c.getName()); |
||
450 | |||
451 | List<String> recipients = new ArrayList<String>(); |
||
452 | for(1.5.0/docs/api/java/lang/String.html">String email:emails) |
||
453 | recipients.add(email); |
||
454 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
455 | } |
||
456 | |||
457 | public Email getUnidadeValidadaEmail(List<String> emails, CourseUnit c, LangEnum langEnum) |
||
458 | { |
||
459 | List<String> arguments = new ArrayList<String>(); |
||
460 | |||
461 | |||
462 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
463 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
464 | |||
465 | if(langEnum == LangEnum.PORTUGUESE) |
||
466 | { |
||
467 | template = Globals.EMAIL_UNDADE_VALIDADA_TEMPLATE_PT; |
||
468 | subject = Globals.EMAIL_UNDADE_VALIDADA_SUBJECT_PT; |
||
469 | } |
||
470 | else |
||
471 | { |
||
472 | template = Globals.EMAIL_UNDADE_VALIDADA_TEMPLATE_EN; |
||
473 | subject = Globals.EMAIL_UNDADE_VALIDADA_SUBJECT_EN; |
||
474 | } |
||
475 | 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()}); |
||
476 | |||
477 | arguments.add(c.getName()); |
||
478 | |||
479 | List<String> recipients = new ArrayList<String>(); |
||
480 | for(1.5.0/docs/api/java/lang/String.html">String email:emails) |
||
481 | recipients.add(email); |
||
482 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
483 | } |
||
484 | |||
485 | public Email getUnidadeEditadaEmail(List<String> emails, CourseUnit c, LangEnum langEnum) |
||
486 | { |
||
487 | List<String> arguments = new ArrayList<String>(); |
||
488 | |||
489 | |||
490 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
491 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
492 | |||
493 | if(langEnum == LangEnum.PORTUGUESE) |
||
494 | { |
||
495 | template = Globals.EMAIL_UNDADE_EDITADA_TEMPLATE_PT; |
||
496 | subject = Globals.EMAIL_UNDADE_EDITADA_SUBJECT_PT; |
||
497 | } |
||
498 | else |
||
499 | { |
||
500 | template = Globals.EMAIL_UNDADE_EDITADA_TEMPLATE_EN; |
||
501 | subject = Globals.EMAIL_UNDADE_EDITADA_SUBJECT_EN; |
||
502 | } |
||
503 | 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()}); |
||
504 | |||
505 | arguments.add(c.getCourseName()); |
||
506 | arguments.add(c.getName()); |
||
507 | |||
508 | List<String> recipients = new ArrayList<String>(); |
||
509 | for(1.5.0/docs/api/java/lang/String.html">String email:emails) |
||
510 | recipients.add(email); |
||
511 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
512 | } |
||
513 | |||
236 | jmachado | 514 | 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) |
515 | { |
||
516 | try |
||
517 | { |
||
518 | sendEmail(getNewGradesEmail(grades,langEnum,studentEmail,studentName)); |
||
519 | return true; |
||
520 | } |
||
521 | catch (ServiceException e) |
||
522 | { |
||
523 | return false; |
||
524 | } |
||
525 | |||
526 | } |
||
527 | |||
528 | public static void main(1.5.0/docs/api/java/lang/String.html">String [] args) |
||
529 | { |
||
440 | jmachado | 530 | 1.5.0/docs/api/java/lang/System.html">System.out.println( DatesUtils.getStringFromDate(new 5+0%2Fdocs%2Fapi+Date">Date())); |
531 | // List<String[]> grades = new ArrayList<String[]>(); |
||
532 | // grades.add(new String[]{"Teste","3"}); |
||
533 | // grades.add(new String[]{"Teste2","4"}); |
||
534 | // new SendEmailService().sendNewGrades(grades,LangEnum.PORTUGUESE,"jmachado@estgp.pt","jorge Machado"); |
||
236 | jmachado | 535 | } |
536 | |||
29 | jmachado | 537 | } |