List of usage examples for javax.mail.internet AddressException getMessage
public String getMessage()
From source file:org.etudes.jforum.util.mail.TopicSpammer.java
public TopicSpammer(Topic topic, Post post, List users, String messageFile) { // Prepare the users. In this current version, the email // is not personalized, so then we'll just use his address List recipients = new ArrayList(); for (Iterator iter = users.iterator(); iter.hasNext();) { User u = (User) iter.next();// w w w . j ava2s. c om try { new InternetAddress(u.getEmail()); } catch (AddressException e) { if (logger.isWarnEnabled()) logger.warn("TopicSpammer(...) : " + u.getEmail() + " is invalid. And exception is : " + e); continue; } recipients.add(u.getEmail()); } // Make the topic url String page = ""; // int postsPerPage = SystemGlobals.getIntValue(ConfigKeys.POST_PER_PAGE); int postsPerPage = SakaiSystemGlobals.getIntValue(ConfigKeys.POST_PER_PAGE); if (topic.getTotalReplies() > postsPerPage) { page += (((topic.getTotalReplies() / postsPerPage)) * postsPerPage) + "/"; } //Mallika-comments beg /*String forumLink = SystemGlobals.getValue(ConfigKeys.FORUM_LINK); if (!forumLink.endsWith("/")) { forumLink += "/"; } String path = forumLink + "posts/list/" + page + topic.getId() + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION) + "#" + topic.getLastPostId(); String unwatch = forumLink + "posts/unwatch/" + topic.getId() + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION); */ //Mallika-comments end SimpleHash params = new SimpleHash(); if (logger.isDebugEnabled()) logger.debug("TopicSpammer- this is the CODE!"); //Mallika - new code beg //String path = null; String sitetitle = null; Site currentSite = null; try { currentSite = SiteService.getSite(ToolManager.getCurrentPlacement().getContext()); sitetitle = currentSite.getTitle(); } catch (Exception e) { //System.out.println("Exception thrown "+e.toString()); logger.error(this.getClass().getName() + ".TopicSpammer() : " + e.getMessage(), e); } //Mallika - new code end params.put("topic", topic); params.put("post", post); params.put("siteTitle", sitetitle); String topicFrom = ""; if (topic.getPostedBy() != null) { topicFrom = topic.getPostedBy().getFirstName() + " " + topic.getPostedBy().getLastName(); } params.put("topicFrom", topicFrom); StringBuilder siteNavUrl = new StringBuilder(); String portalUrl = ServerConfigurationService.getPortalUrl(); params.put("portalUrl", portalUrl); siteNavUrl.append(portalUrl); String currToolId = ToolManager.getCurrentPlacement().getId(); ToolConfiguration toolConfiguration = currentSite.getTool(currToolId); siteNavUrl.append("/"); siteNavUrl.append("site"); siteNavUrl.append("/"); siteNavUrl.append(Web.escapeUrl(currentSite.getId())); if (toolConfiguration != null) { siteNavUrl.append("/"); siteNavUrl.append("page"); siteNavUrl.append("/"); siteNavUrl.append(Web.escapeUrl(toolConfiguration.getPageId())); } //params.put("serverurl", siteNavUrl); params.put("siteToolUrl", siteNavUrl); //Mallika-comments beg /*params.put("forumLink", forumLink); params.put("unwatch", unwatch);*/ //Mallika-comments end //Mallika-code below changed to add course id Object obj[] = new String[] { sitetitle, topic.getTitle() }; /*super.prepareMessage(recipients, params, "[" + path + "] " + MessageFormat.format(SystemGlobals.getValue(ConfigKeys.MAIL_NEW_ANSWER_SUBJECT), new String[] { topic.getTitle() }), SystemGlobals.getValue(ConfigKeys.MAIL_NEW_ANSWER_MESSAGE_FILE));*/ /*super.prepareMessage(recipients, params, "[" + path + "] " + MessageFormat.format(SystemGlobals.getValue(ConfigKeys.MAIL_NEW_ANSWER_SUBJECT), obj), SystemGlobals.getValue(ConfigKeys.MAIL_NEW_ANSWER_MESSAGE_FILE));*/ super.prepareMessage(recipients, params, //"[" + sitetitle + "] " + MessageFormat.format(SystemGlobals.getValue(ConfigKeys.MAIL_NEW_ANSWER_SUBJECT), obj), MessageFormat.format(SystemGlobals.getValue(ConfigKeys.MAIL_NEW_ANSWER_SUBJECT), obj), SystemGlobals.getValue(messageFile)); }
From source file:org.etudes.jforum.view.forum.PrivateMessageAction.java
/** * send private message//from ww w. j a va 2 s . c o m * @param pm - PrivateMessage * @param toUsername - to user name * @param userEmail - user email * @param pmEmailEnabled - is pm enabled * @param toUserId - to user id * @param attachmentIds - attachment Id's * @throws Exception */ private void sendPrivateMessage(PrivateMessage pm, String toUsername, String userEmail, boolean pmEmailEnabled, int toUserId, int attachmentIds[]) throws Exception { if (toUserId == -1) { this.setTemplateName(TemplateKeys.PM_SENDSAVE_USER_NOTFOUND); this.context.put("message", I18n.getMessage("PrivateMessage.userIdNotFound")); return; } User fromUser = DataAccessDriver.getInstance().newUserDAO() .selectById(SessionFacade.getUserSession().getUserId()); pm.setFromUser(fromUser); User toUser = new User(); toUser.setId(toUserId); toUser.setUsername(toUsername); toUser.setEmail(userEmail); pm.setToUser(toUser); boolean preview = (this.request.getParameter("preview") != null); if (!preview) { //DataAccessDriver.getInstance().newPrivateMessageDAO().send(pm); DataAccessDriver.getInstance().newPrivateMessageDAO().saveMessage(pm, attachmentIds); /*this.setTemplateName(TemplateKeys.PM_SENDSAVE); this.context.put("message", I18n.getMessage("PrivateMessage.messageSent", new String[] { this.request.getContextPath() +"/pm/inbox" + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION)}));*/ // If the target user if in the forum, then increments its // private messate count String sid = SessionFacade.isUserInSession(toUserId); if (sid != null) { UserSession us = SessionFacade.getUserSession(sid); us.setPrivateMessages(us.getPrivateMessages() + 1); } if (logger.isDebugEnabled()) logger.debug("Before userEmail"); if (userEmail != null && userEmail.trim().length() > 0) { if (logger.isDebugEnabled()) logger.debug("Useremail is not null " + pmEmailEnabled); //Mallika-commenting line below and going based off of settings instead /*if (SystemGlobals.getBoolValue(ConfigKeys.MAIL_NOTIFY_ANSWERS)) {*/ if ((pmEmailEnabled == true) || (pm.getPriority() == PrivateMessage.PRIORITY_HIGH)) { if (logger.isDebugEnabled()) logger.debug("Sending email"); try { new InternetAddress(toUser.getEmail()); } catch (AddressException e) { if (logger.isWarnEnabled()) logger.warn("sendPrivateMessage(...) : " + toUser.getEmail() + " is invalid. And exception is : " + e); return; } //get attachments List attachments = DataAccessDriver.getInstance().newAttachmentDAO() .selectPMAttachments(pm.getId()); try { if (attachments != null && attachments.size() > 0) { QueuedExecutor.getInstance().execute( new EmailSenderTask(new PrivateMessageSpammer(toUser, pm, attachments))); } else { QueuedExecutor.getInstance() .execute(new EmailSenderTask(new PrivateMessageSpammer(toUser, pm))); } } catch (Exception e) { logger.error(this.getClass().getName() + ".sendSave() : " + e.getMessage(), e); } } } } }
From source file:fi.hoski.remote.ui.Admin.java
private void menuReservation() { menuReservation = new JMenu(); TextUtil.populate(menuReservation, "RESERVATIONS"); menuBar.add(menuReservation);/*from w w w.j a v a 2s .c o m*/ JMenu menuMakeReservation = new JMenu(); TextUtil.populate(menuMakeReservation, "MAKE RESERVATION"); menuReservation.add(menuMakeReservation); JMenu editReservation = new JMenu(); TextUtil.populate(editReservation, "EDIT RESERVATION"); menuReservation.add(editReservation); JMenu mailMenu = new JMenu(); TextUtil.populate(mailMenu, "SEND EMAIL"); menuReservation.add(mailMenu); JMenu smsMenu = new JMenu(); TextUtil.populate(smsMenu, "SEND SMS"); smsMenu.setEnabled(serverProperties.isZonerSMSSupported()); menuReservation.add(smsMenu); for (final EventType eventType : EventType.values()) { ActionListener action = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { reservate(eventType, null); } }; action = createActionListener(frame, action); JMenuItem menuItem = new JMenuItem(); TextUtil.populate(menuItem, eventType.name()); menuItem.addActionListener(action); menuMakeReservation.add(menuItem); JMenuItem editItem = new JMenuItem(); TextUtil.populate(editItem, eventType.name()); ActionListener editAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { editReservations(eventType); } }; editAction = createActionListener(frame, editAction); editItem.addActionListener(editAction); if (Event.isInspection(eventType)) { editItem.setEnabled(accessUser); } editReservation.add(editItem); JMenuItem mailItem = new JMenuItem(); TextUtil.populate(mailItem, eventType.name()); ActionListener mailAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<Event> selected = chooseEvents(eventType, "CHOOSE", true); if (selected != null && selected.size() == 1) { try { Event event = selected.get(0); List<Reservation> reservationList = dss.getReservations(event); Day date = (Day) event.get(Event.EventDate); String subject = TextUtil.getText(eventType.name()) + " " + date; String body = getMessage(eventType.name()); MailDialog md = new MailDialog(frame, subject, body, reservationList); if (md.edit()) { } } catch (AddressException ex) { throw new IllegalArgumentException(ex); } } else { JOptionPane.showMessageDialog(frame, TextUtil.getText("NO SELECTION"), TextUtil.getText("MESSAGE"), JOptionPane.INFORMATION_MESSAGE); } } }; mailAction = createActionListener(frame, mailAction); mailItem.addActionListener(mailAction); mailMenu.add(mailItem); JMenuItem smsItem = new JMenuItem(); TextUtil.populate(smsItem, eventType.name()); ActionListener smsAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<Event> selected = chooseEvents(eventType, "CHOOSE", true); if (selected != null && selected.size() == 1) { try { Event event = selected.get(0); List<Reservation> reservationList = dss.getReservations(event); List<String> phoneList = new ArrayList<String>(); for (Reservation r : reservationList) { String number = (String) r.get(Repository.JASENET_MOBILE); if (number != null) { phoneList.add(number); } } SMSDialog sd = new SMSDialog(frame, TextUtil.getText(eventType.name()), "", phoneList); if (sd.edit()) { } } catch (IOException ex) { JOptionPane.showMessageDialog(frame, ex.getMessage()); } catch (SMSException ex) { JOptionPane.showMessageDialog(frame, ex.getMessage()); } } else { JOptionPane.showMessageDialog(frame, TextUtil.getText("NO SELECTION"), TextUtil.getText("MESSAGE"), JOptionPane.INFORMATION_MESSAGE); } } }; smsAction = createActionListener(frame, smsAction); smsItem.addActionListener(smsAction); smsMenu.add(smsItem); } }
From source file:org.sakaiproject.email.impl.BasicEmailService.java
/** * {@inheritDoc}//from ww w. ja va 2 s.com * * @see org.sakaiproject.email.api.EmailService#send(EmailMessage) */ public List<EmailAddress> send(EmailMessage msg, boolean messagingException) throws AddressValidationException, NoRecipientsException, MessagingException { ArrayList<EmailAddress> invalids = new ArrayList<EmailAddress>(); InternetAddress from = null; // convert and validate the 'from' address try { from = new InternetAddress(msg.getFrom().getAddress(), true); from.setPersonal(msg.getFrom().getPersonal()); } catch (AddressException e) { throw new AddressValidationException("Invalid 'FROM' address: " + msg.getFrom().getAddress(), msg.getFrom()); } catch (UnsupportedEncodingException e) { throw new AddressValidationException("Invalid 'FROM' address: " + msg.getFrom().getAddress(), msg.getFrom()); } // convert and validate reply to addresses InternetAddress[] replyTo = emails2Internets(msg.getReplyTo(), invalids); if (!invalids.isEmpty()) { throw new AddressValidationException("Invalid 'REPLY TO' address", invalids); } /* * LOOK - IF THERE ARE ANY INVALID RECIPIENT, AN EXCEPTION IS THROWN AND THE METHOD EXITS */ // convert and validate the 'to' addresses InternetAddress[] to = emails2Internets(msg.getRecipients(RecipientType.TO), invalids); // convert and validate 'cc' addresses InternetAddress[] cc = emails2Internets(msg.getRecipients(RecipientType.CC), invalids); // convert and validate 'bcc' addresses InternetAddress[] bcc = emails2Internets(msg.getRecipients(RecipientType.BCC), invalids); // convert and validate actual email addresses InternetAddress[] actual = emails2Internets(msg.getRecipients(RecipientType.ACTUAL), invalids); // check that some actual addresses were given. if not, use a compilation of to, cc, bcc if (actual.length == 0) { int total = to.length + cc.length + bcc.length; if (total == 0) { throw new NoRecipientsException( "No valid recipients found on message. Check for invalid email addresses returned from this method."); } actual = new InternetAddress[total]; int count = 0; for (InternetAddress t : to) { actual[count++] = t; } for (InternetAddress c : cc) { actual[count++] = c; } for (InternetAddress b : bcc) { actual[count++] = b; } } // rebundle addresses to expected param type HashMap<RecipientType, InternetAddress[]> headerTo = new HashMap<RecipientType, InternetAddress[]>(); headerTo.put(RecipientType.TO, to); headerTo.put(RecipientType.CC, cc); headerTo.put(RecipientType.BCC, bcc); // convert headers to expected format List<String> headers = msg.extractHeaders(); // build the content type String contentType = EmailHeaders.CONTENT_TYPE + ": " + msg.getContentType(); if (msg.getCharacterSet() != null && msg.getCharacterSet().trim().length() != 0) { contentType += "; charset=" + msg.getCharacterSet(); } // message format is only used when content type is text/plain as specified in the rfc if (ContentType.TEXT_PLAIN.equals(msg.getCharacterSet()) && msg.getFormat() != null && msg.getFormat().trim().length() != 0) { contentType += "; format=" + msg.getFormat(); } // add the content type to the headers headers.add(contentType); // send the message try { sendMailMessagingException(from, actual, msg.getSubject(), msg.getBody(), headerTo, replyTo, headers, msg.getAttachments()); } catch (MessagingException e) { // Just log it, if user doesn't want it thrown if (messagingException == false) { M_log.error("Email.sendMail: exception: " + e.getMessage(), e); } else { throw e; } } return invalids; }