import java.awt.*; import java.applet.Applet; import java.io.IOException; import java.net.ProtocolException; import java.net.UnknownHostException; import Qsmtp; public class SmtpApp extends Applet { private String from = "Uninitialized"; private String to = "Uninitialized"; private String subject = "Uninitialized"; private String message = "Uninitialized"; private String mailhost = "unknown"; Button sendit; Label fromLabel; Label toLabel; TextField fromText, toText; TextField subjText; TextArea mesgText; public String[][] getParameterInfo() { String[][] info = { // Format: ParameterName, ParameterType, ParameterDescription {"To","String","To Address"}, {"From","String","From Address"}, {"Mailhost","String","Mailhost hostname"}, {"EditTo","boolean","Is To editable field (default true)?"}, {"EditFrom","boolean","Is From editable field (default false)?"} }; return info; } public String getAppletInfo() { return "SmtpApp - Applet to send SMTP email, written by Jim Driscoll"; } public void init() { super.init(); resize(300, 200); from = getParameter("From"); to = getParameter("To"); mailhost = getParameter("Mailhost"); fromLabel = new Label("From: "); toLabel = new Label("To: "); fromText = new TextField(from,10); toText = new TextField(to,10); if (getParameter("EditTo") != null && getParameter("EditTo").equals("false")) toText.setEditable(false); else toText.setEditable(true); if (getParameter("EditFrom") != null && getParameter("EditFrom").equals("true")) fromText.setEditable(true); else fromText.setEditable(false); add(fromLabel); add(fromText); add(toLabel); add(toText); subjText = new TextField("Send from Applet", 40); add(subjText); mesgText = new TextArea("Sample Message",5,40); add(mesgText); sendit = new Button("Send"); add(sendit); } public boolean action(Event e, Object o) { if (e.target instanceof Button) { if ("Send".equals( (String) o ) ) { try { /* Nice idea - but for some reason it is locking up... I'll fix it for v1.1 :-) showStatus("Getting Mailhost"); String mailhost = getCodeBase().getHost(); */ showStatus("Connecting to mailhost " + mailhost); Qsmtp connect = new Qsmtp(mailhost); showStatus("Connected to mailhost... sending..."); subject = subjText.getText(); message = mesgText.getText(); connect.sendmsg(from,to,subject,message); showStatus("Message sent"); if (fromText.isEditable()) fromText.setText(getParameter("From")); if (toText.isEditable()) toText.setText(getParameter("To")); subjText.setText("Send from Applet"); mesgText.setText("Sample Message"); } catch (UnknownHostException x1) { showStatus("Failed to find host - " + mailhost); System.out.println(x1.getMessage()); } catch (ProtocolException x2) { showStatus("Some sort of protocol exception"); System.out.println(x2.getMessage()); } catch (IOException x3) { showStatus("Error reading/writing to socket on " + mailhost); System.out.println(x3.getMessage()); } finally { } return true; } } if (e.target instanceof TextField) { return true; } return super.action(e,o); } }