01: package com.jat.presentation.controller.action;
02:
03: import javax.mail.Address;
04: import javax.mail.MessagingException;
05: import javax.mail.internet.InternetAddress;
06: import javax.servlet.http.HttpServletRequest;
07: import javax.servlet.http.HttpServletResponse;
08: import javax.servlet.http.HttpSession;
09:
10: import com.jat.core.log.LogManager;
11: import com.jat.presentation.PresentationException;
12: import com.jat.presentation.controller.Action;
13: import com.jat.util.mail.SendMail;
14:
15: /**
16: * <p>Title: JAT</p>
17: * <p>Description: </p>
18: * <p>Copyright: Copyright (c) 2004 -2005 Stefano Fratini (stefano.fratini@gmail.com)</p>
19: * <p>Distributed under the terms of the GNU Lesser General Public License, v2.1 or later</p>
20: * @author stf
21: * @version 1.0
22: * @since 1.2
23: */
24:
25: public class SendEMailAction extends Action {
26:
27: public void doAction(HttpServletRequest request,
28: HttpServletResponse response) throws PresentationException {
29: HttpSession session = request.getSession();
30: SendMail sm = (SendMail) session.getAttribute("SEND_MAIL");
31: String serverSettings = request.getParameter("serverSettings");
32: if (sm == null
33: || (serverSettings != null && serverSettings
34: .equals("true"))) {
35: String host = request.getParameter("host");
36: String username = request.getParameter("username");
37: String password = request.getParameter("password");
38: sm = new SendMail(host, username, password);
39: session.setAttribute("SEND_MAIL", sm);
40: session.setAttribute("SEND_MAIL.smtp", host);
41: session.setAttribute("SEND_MAIL.username", username);
42: }
43: try {
44: String from = request.getParameter("from");
45: Address fromAddress = null;
46: if (from != null && !from.trim().equals(""))
47: fromAddress = new InternetAddress(from.trim());
48: String subject = request.getParameter("subject");
49: String to = request.getParameter("to");
50: String body = request.getParameter("body");
51: sm.send(fromAddress, subject, to, body);
52: } catch (MessagingException ex) {
53: LogManager.sendWarning(this .getClass().getName()
54: + "::doAction: exception: " + ex);
55: throw new PresentationException(ex.getMessage());
56: }
57: }
58: }
|