<%@ page import="java.io.InputStream" %>
<%@ page import="java.util.Properties" %>
<%@ page import="java.util.Enumeration" %>


<%! 
  Properties database;
%>
<%
  ServletContext ctx;
  InputStream is;
  String dfile;
  dfile="/maillist/addresses.prop";
  database=new Properties();
  ctx=getServletContext();
  is=ctx.getResourceAsStream(dfile);
  if (is==null) 
    out.println("Internal server error " + dfile);
  else
    {
    database.load(is);
    is.close();
    }
%>
<HTML>
<HEAD>
</HEAD>
<BODY BGColor=CornSilk>
<% if (request.getContentLength()==-1) { %>
<H1>Send mail to a group</H1>
<FORM METHOD=POST>

Group: <SELECT NAME=group>
<%
  Enumeration e=database.keys();
  while (e.hasMoreElements())
    {
    String s=(String)e.nextElement();
    out.println("<OPTION VALUE='" + s + "'>"+s);
    }
%>

</SELECT>
<BR>
From: <INPUT NAME=From SIZE=40><BR>
Subject: <INPUT NAME=Subj SIZE=40><BR>
<TEXTAREA ROWS=25 COLS=80 Name=msg>
</TEXTAREA>
<BR>
<INPUT TYPE=SUBMIT VALUE=Send>
</FORM>

<% } else { 
 String elist;
 // really this could come from a database...
 elist=(String)database.getProperty(request.getParameter("group"));
 MailMessage msg=new MailMessage(request.getParameter("From"),elist,
     request.getParameter("Subj"),request.getParameter("msg"));
  SMTP smtp=new SMTP("smtp.myserver.com");  // use yours
  if (smtp.sendMail(msg)==0) {
%>
  Message sent.
<% } else { %>
  An error occured. Please try again.

<% 
  }
} 
%>
</BODY>
</HTML>
