Mercurial Hosting > nabble
view src/nabble/view/web/tools/SendMail.java @ 62:4674ed7d56df default tip
remove n2
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 30 Sep 2023 20:25:29 -0600 |
parents | 7ecd1a4ef557 |
children |
line wrap: on
line source
package nabble.view.web.tools; import fschmidt.util.mail.Mail; import fschmidt.util.mail.MailException; import fschmidt.util.mail.MailHome; import fschmidt.util.mail.PlainTextContent; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; public final class SendMail extends HttpServlet { protected void service(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); boolean sent = false; if( "Post".equals( request.getParameter("Action") ) ) { String mailText = request.getParameter("mail"); String from = request.getParameter("from"); String smtpFrom = request.getParameter("smtp_from"); String to = request.getParameter("to"); String subject = request.getParameter("subject"); Mail mail = MailHome.newMail(); try { mail.setFrom( MailHome.parseAddress(from) ); } catch(MailException e) { throw new RuntimeException("bad 'from' address",e); } try { mail.setTo( MailHome.parseAddress(to) ); } catch(MailException e) { throw new RuntimeException("bad 'to' address",e); } mail.setSubject(subject); mail.setContent(new PlainTextContent(mailText)); if( smtpFrom.equals("") ) { MailHome.getDefaultSmtpServer().send(mail); } else { MailHome.getDefaultSmtpServer().sendFrom(mail,smtpFrom); } sent = true; } out.print( "\r\n<html>\r\n<head>\r\n<title>Send Mail</title>\r\n</head>\r\n<body>\r\n" ); if (sent) { out.print( "\r\n<b>Your mail has been sent.</b><br>\r\n" ); } else { out.print( "\r\n<form method=\"post\" action=\"" ); out.print( (response.encodeURL("SendMail.jtp")) ); out.print( "\" accept-charset=\"UTF-8\">\r\n<input type=\"hidden\" name=\"Action\" value=\"Post\">\r\n<table>\r\n<tr><td>Envelope From</td><td><input type=\"text\" name=\"smtp_from\" size=\"25\"></td></tr>\r\n<tr><td>From:</td><td><input type=\"text\" name=\"from\" size=\"25\"></td></tr>\r\n<tr><td>To:</td><td><input type=\"text\" name=\"to\" size=\"25\" ></td></tr>\r\n<tr><td>Subject:</td><td><input type=\"text\" name=\"subject\" size=\"25\"\"></td></tr>\r\n<tr><td colspan=\"2\"><textarea name=\"mail\" cols=\"72\" rows=\"20\"></textarea></td></tr>\r\n<tr><td><input type=\"submit\" value=\"Send Mail\" /></td></tr>\r\n</table>\r\n</form>\r\n" ); } out.print( "\r\n<br>\r\n<a href=\"/tools/Index.jtp\">back to tools</a>\r\n<br>\r\n</body>\r\n</html>\r\n" ); } }