private void sendMail( HttpServletRequest request, BlogAuthor blogAuthor, Entity blog, Settings settings) throws IOException { if (settings.dontSendEmail()) { return; } try { String digest = DS.getBlogDigest(blog); MailService mailService = MailServiceFactory.getMailService(); Message reply = new Message(); reply.setSender(blogAuthor.toString()); Email sender = (Email) blog.getProperty(SenderProperty); reply.setTo(sender.getEmail()); String subject = (String) blog.getProperty(SubjectProperty); reply.setSubject("Blog: " + subject + " received"); StringBuilder sb = new StringBuilder(); URI reqUri = new URI(request.getScheme(), NamespaceManager.get(), "", ""); if (!settings.isPublishImmediately()) { sb.append("<div>"); sb.append( "<p>Blog is not yet published because it was sent from untrusted email address " + sender.getEmail() + ". </p>"); URI publishUri = reqUri.resolve( "/blog?action=publish&blog=" + KeyFactory.keyToString(blog.getKey()) + "&auth=" + digest); sb.append("<a href=\"" + publishUri.toASCIIString() + "\">Publish Blog</a>"); sb.append("</div>"); } sb.append("<div>"); sb.append("<p>If blog is not ok, you can delete and then resend it.</p>"); URI deleteUri = reqUri.resolve( "/blog?action=remove&blog=" + KeyFactory.keyToString(blog.getKey()) + "&auth=" + digest); sb.append("<a href=\"" + deleteUri.toASCIIString() + "\">Delete Blog</a>"); sb.append("</div>"); reply.setHtmlBody(sb.toString()); mailService.send(reply); } catch (URISyntaxException ex) { throw new IOException(ex); } }
public static void notifyChange(Inspeccion inspeccion, Integer action) { try { MailService service = MailServiceFactory.getMailService(); MailService.Message msg = new MailService.Message(); msg.setSender("*****@*****.**"); // Segun el tipo de accion que se ejecuto cambian los destinatarios. InspeccionMailStrategy strategy = new ObservadoStrategy().getStrategy(action); strategy.exec(inspeccion, msg); msg.setSubject( "Detalle de inspeccion n°: " + inspeccion.getId() + " estado:" + inspeccion.getState().toString()); // msg.setContent(InspeccionHMTL.getInspeccionHTML(inspeccion),"text/html"); // http://127.0.0.1:8888/createpdfservlet CustomWorker cworker = new CustomWorker(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { cworker.exec(bos, new StringReader(InspeccionHMTL.getInspeccionHTML(inspeccion))); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } msg.setTextBody("Detalle de inspeccion Adjunto en formato PDF"); Attachment a = new Attachment("reporte.pdf", bos.toByteArray()); msg.setAttachments(a); service.send(msg); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public static Momin findOrCreateUser(Momin user) throws TaskException { TaskDao dao = new TaskDao(); Momin m = dao.getMomin(user.getId()); // utilisateur n'existe pas dans la base if (m == null) { if (user.getId().charAt(0) != 'f') { UserService usrSrvc = UserServiceFactory.getUserService(); User u = usrSrvc.getCurrentUser(); user.setEmail(u.getEmail()); // user.setId(u.getUserId()); user.setName(u.getNickname()); } dao.save(user); m = user; MailService mailService = MailServiceFactory.getMailService(); Message message = new Message( "*****@*****.**", "*****@*****.**", "Un nouveau utilisateur ", user.getEmail() + " " + user.getName() + " a accéder à l'application pour la première fois"); try { mailService.send(message); } catch (IOException e) { e.printStackTrace(); } } m = m.clon(); // // m.setFriendsCalendar(Arrays.asList("105208827974973865566�&#naitsoft","110949677754069966012�&#sharpensoul","18580476422013912411�&#test","11701531798136846518�&#test1")); return m; }
public AppEngineGuiceModule withMailService() { this.mailService = MailServiceFactory.getMailService(); return this; }