FormMail servlet 2.5


    It is a Java servlet allows you to email any html forms. You must set this servlet as an action parameter for your form. Servlet collects posted data and processes them according to own configuration file. Configuration file (or template file) describes how your mail looks like, what is your smtp server etc.

How to use it:

a) copy formMailPackage.jar into WEB-INF/lib directory

b) describe servlet in your web.xml file:
 


    <servlet>
     <servlet-name>FormMailServlet</servlet-name>
     <servlet-class>com.jsos.formmail.FormMailServlet</servlet-class>
    </servlet>

You can pass template file as a parameter to this servlet and use it in this form:
 


    http://your_host/servlet/FormMailServlet?template_file

E.g.:
 


<form method=post action="http://your_host/servlet/FormMailServlet?c:\template1.txt">
To:<input type=text name=to><br>
Subj:<input type=text name=subj><br>
<textarea rows=5 cols=30 name=body>
</textarea><br>
<input type=submit value=Send>
</form>

or you may describe template file as an initial parameter (parameter name is config):
 


    <servlet>
     <servlet-name>FormMailServlet</servlet-name>
     <servlet-class>com.jsos.formmail.FormMailServlet</servlet-class>
     <init-param>
      <param-name>config</param-name>
      <param-value>path_to_your_template_file</param-value>
     </init-param>
    </servlet>

and use servlet in this form:
 

    http://your_host/servlet/FormMailServlet

E.g.:
 

<form method=post action="http://your_host/servlet/FormMailServlet">
  To:<input type=text name=to><br>
  Subj:<input type=text name=subj><br>
  <textarea rows=5 cols=30 name=body>
  </textarea><br>
  <input type=submit value=Send>
</form>

    Template file describes mail your settings as well as a template for your mail. Template file is a text file. In this file you can set address of your smtp relay, smtp port, domain and describe contents of the letter. When you describe contents you can use values of fields from your form. Letter will be composed dynamically, when you submit this form.
    Template file has got free format, but description of any parameter must starts with an appropriate reserved word on the new line.
    Current version supports the following list of parameters:

    Mailhost: describes your smtp host. This parameter is mandatory
    Port: describes smtp port. By default it is 25.
    Domain: describes your domain. This parameter is mandatory
    From: describes source address. This parameter is mandatory
    To: describes destination address. This parameter is mandatory
    Cc: describes cc settings for your letter
    Subject: set letter's subject
    Body: set letter's body
    Attach: you can set here a list of files you need to attach to composed letter.
    Reply: you can set here an url for the page that will be displayed after the mail sending. See also Notes below.
    Encoding: Localization support. You can set character encoding for input parameters here. Default value is ISO-8859-1. E.g.: Encoding:Cp1251
    Html: describes format. Possible values are true or false. If this value if true servlet will send letter in HTML format. Default value is false.

    When you describe contents of any field in your configuration file, you can use constructions like $FormFieldName as a reference for the value of the appropriate form's field. E.g. for the above mentioned example you can set some like this:
To: $to
Subject: Re:$subj
Body: $body

here $to will be replaced with the actual value for the field named to in the submitted form, $subj will be replaced with the value of field named subj etc.
    When you describe body field you can use also construction like:
    $file=path_to_some_text_file
    Content of this file will be added to the body of composed letter.

    When you set attachments you can use a list of files. Files should be separated by commas.

Notes:

1. Servlet's configuration file can be saved anywhere on your server. E.g. if you are using FormMailServlet?config line we assume this file is saved under the root directory of your servletrunner. But you can of course always use the full path for setting config file location: FormMailServlet?/home/users/my_file (or FormMailServlet?c:\users\my_file)

2. If reply value starts with http than request will be redirected to that site. Otherwise servlet assumes a local resource and forwards request.
 

    For downloading:  formMailPackage.jar  
    Sample of configuration file:  formconf
 

  © Coldbeans    Comments?

See also JSOS - the largest collection of servlets and filters.

Also in JSOS: