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