Mercurial Hosting > nabble
view src/nabble/view/web/tools/SendMail.jtp @ 0:7ecd1a4ef557
add content
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 21 Mar 2019 19:15:52 -0600 |
parents | |
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; } %> <html> <head> <title>Send Mail</title> </head> <body> <% if (sent) { %> <b>Your mail has been sent.</b><br> <% } else { %> <form method="post" action="<%=response.encodeURL("SendMail.jtp")%>" accept-charset="UTF-8"> <input type="hidden" name="Action" value="Post"> <table> <tr><td>Envelope From</td><td><input type="text" name="smtp_from" size="25"></td></tr> <tr><td>From:</td><td><input type="text" name="from" size="25"></td></tr> <tr><td>To:</td><td><input type="text" name="to" size="25" ></td></tr> <tr><td>Subject:</td><td><input type="text" name="subject" size="25""></td></tr> <tr><td colspan="2"><textarea name="mail" cols="72" rows="20"></textarea></td></tr> <tr><td><input type="submit" value="Send Mail" /></td></tr> </table> </form> <% } %> <br> <a href="/tools/Index.jtp">back to tools</a> <br> </body> </html> <% } } %>