JSP - Input form -> Email Issue
843838Sep 27 2005 — edited Sep 29 2005Good Morning Everyone,
I have an input form that has 6 input boxes, seperated in 2 groups. Names and Email addresses.
I am currently attempting to send the input values to the JSP page as an array, which will then be looped emailing each user that i have previously entered from the first page.
The problem comes if i dont input values in all the forms on the first page i get an error. If it is all filled out then it all goes fine and dandy.
I have edited the html code down to protext page size.
HTML page.
<form action="formname.jsp" method="POST">
<table>
<tr><td>
Name <input type="text" name="name" value=""></td>
<td>
Email <input type="text" name="email" value=""></td>
</tr>
<tr><td>
Name 2<input type="text" name="name" value=""></td>
<td>
Email 2<input type="text" name="email" value=""></td>
</tr>
<tr><td>
Name 3<input type="text" name="name" value=""></td>
<td>
Email 3<input type="text" name="email" value=""></td>
<td colspan="2">
<input type="submit" name="submit" value="Select"></td>
JSP Page
<body>
<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
<%
// define variables and assign values to variables
String[] nName = request.getParameterValues("name");
String[] nEmail = request.getParameterValues("email");
// print by iterating through array
for(int counter = 0; counter < nName.length; counter++)
{
Properties props = new Properties();
props.put("mail.smtp.host", "localhost");
Session s = Session.getInstance(props,null);
MimeMessage message = new MimeMessage(s);
InternetAddress from = new InternetAddress("info@peopletelecom.com.au");
message.setFrom(from);
InternetAddress to = new InternetAddress(nEmail[counter]);
message.addRecipient(Message.RecipientType.TO, to);
message.setSubject(nName[counter]);
message.setText("Mail Message Body!");
Transport.send(message);
}
%>
<p align="center">The Message has been sent.</p>
</body>
Edited Error Code
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Illegal address
~~
root cause
javax.mail.internet.AddressException: Illegal address in string ``''
<end>
So the above error message happens if i dont put data in all of the input forms, but if i do it has no error. The mail will get sent to the addresses i have specified but will come up with an error if only one is inputed with a name.
Also how would i also add a html email to this, instead of plain text.
Thanks!