4. Try to write the first sender Program
We have already introduced JavaMail. Next we can try to write our own program.
First, we should first write an HTML program index.htm for writing mail, as shown below:
Bytes -------------------------------------------------------------------------------------------
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> email writing </title>
</Head>
<Body>
<Form name = "form1" method = "post" action = "testmail. jsp">
<Table width = "75" border = "0" align = "center" cellspacing = "1" bgcolor = "#006600" class = "black">
<Tr bgcolor = "# FFFFFF">
<Td width = "24%"> recipient address: </td>
& Lt; td width = "76%" & gt;
<Input name = "to" type = "text" id = "to"> </td>
</Tr>
<Tr bgcolor = "# FFFFFF">
<Td> topic: </td>
<Td>
<Input name = "title" type = "text" id = "title"> </td>
</Tr>
<Tr>
<Td height = "107" colspan = "2" bgcolor = "# FFFFFF">
<Textarea name = "content" cols = "50" rows = "5" id = "content"> </textarea> </td>
</Tr>
<Tr align = "center">
<Td colspan = "2" bgcolor = "# FFFFFF">
<Input type = "submit" name = "Submit" value = "send">
<Input type = "reset" name = "Submit2" value = "reset">
</Td>
</Tr>
</Table>
</Form>
</Body>
</Html>
Next, we will write another processing program testmail. jsp, as shown below:
Bytes -----------------------------------------------------------------------------------------
<% @ Page contentType = "text/html; charset = GB2312" %>
<% Request. setCharacterEncoding ("gb2312"); %> <! -- Chinese processing code -->
<! -- Introduce the class library to be used -->
<% @ Page import = "java. util. *, javax. mail. *" %>
<% @ Page import = "javax. mail. internet. *" %>
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">