@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { List<String> paths = computeRequestPath(request); if( paths.size() < 1 ) { JSONObject result = mailActions.getWelcome(); sendJsonResponse(response, result); } else { throw new Exception("Unrecognized request"); } } catch (Exception e) { reportError(e, response); } }
private List<MailRecipient> getRecipientsForDestination(String destination) throws Exception { if( null == destination ){ destination = "default"; } List<MailRecipient> recipients = mailRecipients.getRecipientsForDestination(destination); if( recipients.size() < 1 ){ recipients = mailRecipients.getDefaultRecipients(); } return recipients; } }
static public MailRecipient parseString(String value){ String[] components = value.split("\\|"); if( components.length > 1 ){ return new MailRecipient( components[0].trim(), components[1].trim() ); } return new MailRecipient(components[0].trim()); }
recipients.add( new MailRecipient(emailAddress) ); MailMessage message = new MailMessage(); message.setFromAddress(fromAddress); message.addToRecipient( recipient ); passwordReminderGenerator.generateMessage(message, parameters); mailDelivery.sendMessage(message);
@Override public void generateMessage( MailMessage message, Map<String,String> parameters ) throws Exception { String password = parameters.get("password"); // Subject message.setSubject("Nunaliit Password Reminder"); // Create HTML body part StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println("<html><head><title>Nunaliit Password Reminder</title></head><body><h1>Nunaliit Password Reminder</h1>"); pw.println("<p>You requested an e-mail with a reminder of your password to access a Nunaliit atlas.</p>"); pw.println("<p>Your password is: "+password+"</p>"); pw.println("</body></html>"); pw.flush(); message.setHtmlContent(sw.toString()); } }
JSONObject result = new JSONObject(); List<MailRecipient> recipients = getRecipientsForDestination(destination); if( recipients.size() < 1 ){ throw new Exception("Unable to send form e-mail because no recipients are set: "+destination); MailMessage message = new MailMessage(); message.addToRecipient( recipient ); formEmailGenerator.generateMessage(message, parameters); mailDelivery.sendMessage(message);
@Override public void init(ServletConfig config) throws ServletException { super.init(config); // Pick up configuration Object configurationObj = config.getServletContext().getAttribute(MailServletConfiguration.CONFIGURATION_KEY); if( null == configurationObj ) { throw new ServletException("Can not find configuration object"); } if( configurationObj instanceof MailServletConfiguration ){ configuration = (MailServletConfiguration)configurationObj; mailActions = new MailServiceActions( configuration.getAtlasName(), configuration.getMailDelivery(), configuration.getRecipients() ); MailMessageGenerator formEmailGenerator = configuration.getFormEmailGenerator(); if( null != formEmailGenerator ){ mailActions.setFormEmailGenerator(formEmailGenerator); } } else { throw new ServletException("Invalid class for configuration: "+configurationObj.getClass().getName()); } }
public void setMailProperties(Properties mailProperties) throws Exception { this.mailProperties = mailProperties; Set<String> propertyNames = mailProperties.stringPropertyNames(); for(String propName : propertyNames) { try { if( "upload.sender".equals(propName) ) { String value = mailProperties.getProperty(propName); MailRecipient r = MailRecipient.parseString(value); fromAddress = r.getInternetAddress(); } else if( "user.sender".equals(propName) ) { String value = mailProperties.getProperty(propName); MailRecipient r = MailRecipient.parseString(value); fromAddress = r.getInternetAddress(); } } catch(Exception e) { throw new Exception("Problem while parsing key: "+propName, e); } } }
public UserMailNotificationImpl(MailDelivery mailDelivery){ this.mailDelivery = mailDelivery; Properties props = mailDelivery.getMailProperties(); fromAddress = MailRecipient.parseString(value);
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { List<String> paths = computeRequestPath(request); JSONObject result = mailActions.sendFormEmail(destination, subject, contact, body); sendJsonResponse(response, result); reportError(e, response);
public void parseMailProperties(Properties mailProperties) throws Exception { Set<String> propertyNames = mailProperties.stringPropertyNames(); for(String propName : propertyNames) { try { if( "upload.sendNotification".equals(propName) ) { sendUploadMailNotification = Boolean.parseBoolean( mailProperties.getProperty(propName) ); logger.info("sendUploadMailNotification: "+sendUploadMailNotification); } else if( "upload.sender".equals(propName) ) { String value = mailProperties.getProperty(propName); MailRecipient r = MailRecipient.parseString(value); fromAddress = r; } else if( "upload.submission.url".equals(propName) ) { submissionPageLink = mailProperties.getProperty(propName); logger.info("Submission Page URL: "+submissionPageLink); } } catch(Exception e) { throw new Exception("Problem while parsing key: "+propName, e); } } }
public JSONObject getWelcome() throws Exception { JSONObject result = new JSONObject(); result.put("ok", true); result.put("service", "mail"); if( null != mailDelivery && mailDelivery.isConfigured() ){ result.put("configured", true); } if( null != mailRecipients ){ int count = getRecipientsForDestination(null).size(); result.put("defaultRecipientCount", count); } return result; }
recipients.add( new MailRecipient(emailAddress) ); MailMessage message = new MailMessage(); message.setFromAddress(fromAddress); message.addToRecipient( recipient ); passwordRecoveryGenerator.generateMessage(message, parameters); mailDelivery.sendMessage(message);
@Override public void generateMessage( MailMessage message, Map<String, String> parameters ) throws Exception { String submissionDocId = parameters.get("submissionDocId"); String submissionPageLink = parameters.get("submissionPageLink"); // Subject if( null == submissionDocId ) { message.setSubject("Uploaded Submission - <unknown>"); } else { message.setSubject("Uploaded Submission - "+submissionDocId); } // Create HTML body part StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println("<html><head><title>Submission Notification</title></head><body><h1>Submission Notification</h1>"); pw.println("<p>A new dataabse submission media was uploaded to the atlas, which requires your approval.</p>"); if( null != submissionPageLink ) { pw.println("<p>The page where submissions can be approved is located at: <a href=\""+submissionPageLink+"\">"+submissionPageLink+"</a></p>"); } pw.println("</body></html>"); pw.flush(); message.setHtmlContent(sw.toString()); }
private List<MailRecipient> recipientsFromUser(Collection<UserDocument> users){ List<MailRecipient> recipients = new ArrayList<MailRecipient>(users.size()); for(UserDocument user : users){ String display = user.getDisplayName(); Collection<String> emails = user.getEmails(); for(String email : emails){ if( null == display ) { recipients.add( new MailRecipient(email) ); } else { recipients.add( new MailRecipient(email,display) ); } } } return recipients; } }
recipients.add( new MailRecipient(emailAddress) ); MailMessage message = new MailMessage(); message.setFromAddress(fromAddress); message.addToRecipient( recipient ); userCreationGenerator.generateMessage(message, parameters); mailDelivery.sendMessage(message);
@Override public void generateMessage( MailMessage message, Map<String,String> parameters ) throws Exception { String link = parameters.get("link"); // Subject message.setSubject("Nunaliit User Creation"); // Create HTML body part StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println("<html><head><title>Nunaliit User Creation</title></head><body><h1>Nunaliit User Creation</h1>"); pw.println("<p>Someone has requested to create a user for a Nunaliit Atlas. If it"); pw.println("was you, please follow the link below to complete the registration process.</p>"); pw.println("<p>If you did not request a user to be created, simply disregard this e-mail.</p>"); pw.println("<p>To complete the registration process, click on the link below, or paste"); pw.println("it in your favourite web browser.</p>"); pw.println("<p><a href=\""+link+"\">"+link+"</a></p>"); pw.println("</body></html>"); pw.flush(); message.setHtmlContent(sw.toString()); }
@Override public void generateMessage( MailMessage message, Map<String,String> parameters ) throws Exception { String link = parameters.get("link"); // Subject message.setSubject("Nunaliit Password Recovery"); // Create HTML body part StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println("<html><head><title>Nunaliit Password Recovery</title></head><body><h1>Nunaliit Password Recovery</h1>"); pw.println("<p>A password recovery was requested for your Nunaliit account. If you"); pw.println("wish to complete the password recovery process, follow the link provided below.</p>"); pw.println("<p>If you did not request a password recovery, simply ignore this e-mail.</p>"); pw.println("<p>To complete password recovery, click on the link below, or paste"); pw.println("it in your favourite web browser.</p>"); pw.println("<p><a href=\""+link+"\">"+link+"</a></p>"); pw.println("</body></html>"); pw.flush(); message.setHtmlContent(sw.toString()); } }
@Override public void generateMessage( MailMessage message, Map<String,String> parameters ) throws Exception { String docId = parameters.get("docId"); String attachmentName = parameters.get("attachmentName"); String approvalPageLink = parameters.get("approvalPageLink"); // Subject message.setSubject("Uploaded Media - "+docId); // Create HTML body part StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println("<html><head><title>Upload Notification</title></head><body><h1>Upload Notification</h1>"); pw.println("<p>A media was uploaded to the atlas with the following details:</p>"); pw.println("<table>"); pw.println("<tr><td>ID</td><td>"+docId+"</td></tr>"); pw.println("<tr><td>Attachment</td><td>"+attachmentName+"</td></tr>"); pw.println("</table>"); if( null != approvalPageLink ) { pw.println("<p>The page where uploaded media can be approved is located at: <a href=\""+approvalPageLink+"\">"+approvalPageLink+"</a></p>"); } pw.println("</body></html>"); pw.flush(); message.setHtmlContent(sw.toString()); }
@Override public void generateMessage( MailMessage message, Map<String,String> parameters ) throws Exception { int count = Integer.parseInt( parameters.get("count") ); String approvalPageLink = parameters.get("approvalPageLink"); // Subject message.setSubject("Uploaded Media - "+count+" file"+(count>1?"s":"")+" pending for approval"); // Create HTML body part StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println("<html><head><title>Upload Notification</title></head><body><h1>Upload Notification</h1>"); pw.println("<p>A number of files ("+count+") were uploaded to the atlas. Your approval is required.</p>"); if( null != approvalPageLink ) { pw.println("<p>The page where uploaded files can be approved is located at: <a href=\""+approvalPageLink+"\">"+approvalPageLink+"</a></p>"); } pw.println("</body></html>"); pw.flush(); message.setHtmlContent(sw.toString()); }