catch (Exception e)
catch (IOException e) { getLogger().log(Level.WARNING, "JavaMail client error", e); } catch (NoSuchProviderException e) { getLogger().log(Level.WARNING, "JavaMail client error", e); } catch (AddressException e) { getLogger().log(Level.WARNING, "JavaMail client error", e); } catch (MessagingException e) { getLogger().log(Level.WARNING, "JavaMail client error", e); } catch (SAXException e) { getLogger().log(Level.WARNING, "JavaMail client error", e); } catch (URISyntaxException e) { getLogger().log(Level.WARNING, "JavaMail client error", e); } catch (ParserConfigurationException e)
	public void handle(Request request, Response response)	{		try		{			// Parse the SMTP URI			URI smtpURI = new URI(request.getResourceRef().toString());			String smtpHost = smtpURI.getHost();			int smtpPort = smtpURI.getPort();			// String smtpUserInfo = smtpURI.getUserInfo();			if (smtpPort == -1)			{				if ((getClient().getProtocols().equals(Protocol.SMTP))						|| (getClient().getProtocols().equals(Protocol.SMTP_STARTTLS)))				{					// Use the default SMTP port					smtpPort = 25;				}				else if (getClient().getProtocols().equals(Protocol.SMTPS))				{					smtpPort = 465;				}			}			if ((smtpHost == null) || (smtpHost.equals("")))			{				throw new IllegalArgumentException("Invalid SMTP host specified");			}			// Parse the email to extract necessary info			DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance()					.newDocumentBuilder();			Document email = docBuilder.parse(request.getEntity().getStream());			Element root = (Element) email.getElementsByTagName("email").item(0);			Element header = (Element) root.getElementsByTagName("head").item(0);			String subject = header.getElementsByTagName("subject").item(0).getTextContent();			String from = header.getElementsByTagName("from").item(0).getTextContent();			NodeList toList = header.getElementsByTagName("to");			String[] to = new String[toList.getLength()];			for (int i = 0; i < toList.getLength(); i++)			{				to[i] = toList.item(i).getTextContent();			}			NodeList ccList = header.getElementsByTagName("cc");			String[] cc = new String[ccList.getLength()];			for (int i = 0; i < ccList.getLength(); i++)			{				cc[i] = ccList.item(i).getTextContent();			}			NodeList bccList = header.getElementsByTagName("bcc");			String[] bcc = new String[bccList.getLength()];			for (int i = 0; i < bccList.getLength(); i++)			{				bcc[i] = bccList.item(i).getTextContent();			}			String text = root.getElementsByTagName("body").item(0).getTextContent();			// Prepare the connection to the SMTP server			Session session = null;			Transport transport = null;			Properties props = System.getProperties();			// Check if authentication required			boolean authenticate = ((getLogin(request) != null) && (getPassword(request) != null));			// Connect to the SMTP server			if (getClient().getProtocols().equals(Protocol.SMTP)					|| getClient().getProtocols().equals(Protocol.SMTP_STARTTLS))			{				props.put("mail.smtp.host", smtpHost);				props.put("mail.smtp.port", Integer.toString(smtpPort));				props.put("mail.smtp.auth", Boolean.toString(authenticate).toLowerCase());				props.put("mail.smtp.starttls.enable", Boolean.toString(						getClient().getProtocols().equals(Protocol.SMTP_STARTTLS))						.toLowerCase());				session = Session.getDefaultInstance(props);				// session.setDebug(true);				transport = session.getTransport("smtp");			}			else if (getClient().getProtocols().equals(Protocol.SMTPS))			{				props.put("mail.smtps.host", smtpHost);				props.put("mail.smtps.port", Integer.toString(smtpPort));				props.put("mail.smtps.auth", Boolean.toString(authenticate).toLowerCase());				session = Session.getDefaultInstance(props);				// session.setDebug(true);				transport = session.getTransport("smtps");			}			// Check if authentication is needed			if (authenticate)			{				transport.connect(smtpHost, getLogin(request), getPassword(request));			}			else			{				transport.connect();			}			// Actually send the message			if (transport.isConnected())			{				getLogger()						.info(								"JavaMail client connection successfully established. Attempting to send the message");				// Create a new message				Message msg = new MimeMessage(session);				// Set the FROM and TO fields				msg.setFrom(new InternetAddress(from));				for (String element : to)				{					msg.addRecipient(Message.RecipientType.TO, new InternetAddress(element));				}				for (String element : cc)				{					msg.addRecipient(Message.RecipientType.CC, new InternetAddress(element));				}				for (String element : bcc)				{					msg.addRecipient(Message.RecipientType.BCC, new InternetAddress(element));				}				// Set the subject and content text				msg.setSubject(subject);				msg.setText(text);				msg.setSentDate(new Date());				msg.saveChanges();				// Send the message				transport.sendMessage(msg, msg.getAllRecipients());				transport.close();				getLogger().info("JavaMail client successfully sent the message.");			}		}		catch (Exception e)		{			getLogger().log(Level.WARNING, "JavaMail client error", e);		}	}