Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2003
    Posts
    4

    Unanswered: Mass Mailing for text and html in jsp

    Hi,

    I have writting a code for mass mailing. However when sending in html, the receiver get the page in distorted manner, is there anything wrong with the jsp codes, please advise.

    <tr>
    <td class="Header"> Mass Mailing</td>
    </tr>
    </table
    ><table width="770" border="0" align="center" cellpadding="2" cellspacing="1" class="table">

    <tr>
    <td bgcolor="#B0D8DF" class="tableHeader"><B><font color="#FF0000">*</font></B>Enter
    Recipient List File</td>
    <td width="531" bgcolor="#eeeeee"> <input type="file" name="FILE1">
    (CSV format only)</td>
    </tr>
    <tr>
    <td bgcolor="#B0D8DF" class="tableHeader"><B><font color="#FF0000">*</font></B>Enter
    Message File</td>
    <td bgcolor="#eeeeee"> <input TYPE="file" NAME="FILE2"> </td>
    </tr>
    <tr>
    <td height="25" bgcolor="#B0D8DF" class="tableHeader"><B><font color="#FF0000">*</font></B>File
    Type</td>
    <td bgcolor="#eeeeee"><select name="file_type">
    <option selected>--------Please Select---------</option>
    <option value="html">HTML</option>
    <option value="text">Text</option>
    </select></td>
    </tr>
    <tr>
    <td bgcolor="#B0D8DF" class="tableHeader"><B><font color="#FF0000">*</font></B>Subject</td>
    <td bgcolor="#eeeeee"> <input name="subject" type="Text" value="" size="40">
    </td>
    </tr>
    <tr>
    <td height="25" bgcolor="#B0D8DF" class="tableHeader"><B><font color="#FF0000">*</font></B>Sender
    name</td>
    <td bgcolor="#eeeeee"> <input name="sendername" type="Text" value=""> </td>
    </tr>
    <tr>
    <td bgcolor="#B0D8DF" class="tableHeader"><B><font color="#FF0000">*</font></B>Sender
    Email</td>
    <td bgcolor="#eeeeee"> <input name="senderaddress" type="Text" value="">
    </td>
    </tr>
    <tr>
    <td bgcolor="#B0D8DF" class="tableHeader">Body Text</td>
    <td bgcolor="#eeeeee"> <textarea name="body" cols=45 rows=6></textarea>
    </td>
    </tr>
    <tr>
    <td colspan="2" bgcolor="#B0D8DF" class="tableHeader"><div align="center">
    <input type="submit" value="Send" name="submit">
    </div></td>
    </tr>
    </table>

  2. #2
    Join Date
    Dec 2003
    Posts
    4

    Re: Mass Mailing for text and html in jsp

    Originally posted by kensolo
    Hi,

    I have writting a code for mass mailing. However when sending in html, the receiver get the page in distorted manner, is there anything wrong with the jsp codes, please advise.

    <tr>
    <td class="Header"> Mass Mailing</td>
    </tr>
    </table
    ><table width="770" border="0" align="center" cellpadding="2" cellspacing="1" class="table">

    <tr>
    <td bgcolor="#B0D8DF" class="tableHeader"><B><font color="#FF0000">*</font></B>Enter
    Recipient List File</td>
    <td width="531" bgcolor="#eeeeee"> <input type="file" name="FILE1">
    (CSV format only)</td>
    </tr>
    <tr>
    <td bgcolor="#B0D8DF" class="tableHeader"><B><font color="#FF0000">*</font></B>Enter
    Message File</td>
    <td bgcolor="#eeeeee"> <input TYPE="file" NAME="FILE2"> </td>
    </tr>
    <tr>
    <td height="25" bgcolor="#B0D8DF" class="tableHeader"><B><font color="#FF0000">*</font></B>File
    Type</td>
    <td bgcolor="#eeeeee"><select name="file_type">
    <option selected>--------Please Select---------</option>
    <option value="html">HTML</option>
    <option value="text">Text</option>
    </select></td>
    </tr>
    <tr>
    <td bgcolor="#B0D8DF" class="tableHeader"><B><font color="#FF0000">*</font></B>Subject</td>
    <td bgcolor="#eeeeee"> <input name="subject" type="Text" value="" size="40">
    </td>
    </tr>
    <tr>
    <td height="25" bgcolor="#B0D8DF" class="tableHeader"><B><font color="#FF0000">*</font></B>Sender
    name</td>
    <td bgcolor="#eeeeee"> <input name="sendername" type="Text" value=""> </td>
    </tr>
    <tr>
    <td bgcolor="#B0D8DF" class="tableHeader"><B><font color="#FF0000">*</font></B>Sender
    Email</td>
    <td bgcolor="#eeeeee"> <input name="senderaddress" type="Text" value="">
    </td>
    </tr>
    <tr>
    <td bgcolor="#B0D8DF" class="tableHeader">Body Text</td>
    <td bgcolor="#eeeeee"> <textarea name="body" cols=45 rows=6></textarea>
    </td>
    </tr>
    <tr>
    <td colspan="2" bgcolor="#B0D8DF" class="tableHeader"><div align="center">
    <input type="submit" value="Send" name="submit">
    </div></td>
    </tr>
    </table>
    The send out code as follows:
    <%

    // Variables
    int count=0;
    String key="";
    String[] values=new String[10];
    String e_mail="";
    String e_name="";
    String[] e_sender=new String[1];
    String[] file_type=new String[1];
    String[] e_body=new String[1];
    String[] e_subject=new String[1];
    String[] e_sender_name=new String[1];
    String content_mail="";
    String content_file="";
    String thisLine="";

    // Initialization
    mySmartUpload.initialize(pageContext);
    mySmartUpload.setTotalMaxFileSize(100000);
    // Upload
    mySmartUpload.upload();
    try {

    count = mySmartUpload.save("d:/upload");
    } catch (Exception e) {
    out.println(e.toString()); }

    // Retreive Requests' names
    java.util.Enumeration e = mySmartUpload.getRequest().getParameterNames();

    // Retreive parameters
    while (e.hasMoreElements()) {

    key = (String)e.nextElement();
    if(key.equals("senderaddress")) e_sender= mySmartUpload.getRequest().getParameterValues(key) ;
    if(key.equals("file_type")) file_type= mySmartUpload.getRequest().getParameterValues(key) ;
    if(key.equals("body")) e_body= mySmartUpload.getRequest().getParameterValues(key) ;
    if(key.equals("subject")) e_subject= mySmartUpload.getRequest().getParameterValues(key) ;
    if(key.equals("sendername")) e_sender_name= mySmartUpload.getRequest().getParameterValues(key) ;

    }

    //read the file
    BufferedReader br = new BufferedReader(new FileReader("d:/upload/" + mySmartUpload.getFiles().getFile(1).getFileName()) );
    //BufferedReader br = new BufferedReader(new FileReader("c:/ha1ha2ha3.htm"));
    while ((thisLine = br.readLine()) != null) {
    content_file=content_file+br.readLine();
    }
    int idx = 1;
    if (!mySmartUpload.getFiles().getFile(0).isMissing()) {
    DataFile read = DataFile.createReader("8859_1");
    read.setDataFormat(new CSVFormat());
    try {
    read.open(new java.io.File("d:/upload/" + mySmartUpload.getFiles().getFile(0).getFileName()) );

    for (DataRow row = read.next();
    row != null;
    row = read.next()) {

    e_mail = row.getString(0);
    e_name = row.getString(1);

    Properties props = new Properties();
    props.put("mail.smtp.host", smtp_host);
    Session s = Session.getInstance(props,null);
    MimeMessage message = new MimeMessage(s);
    InternetAddress from = new InternetAddress(e_sender[0]);
    message.setFrom(from);
    InternetAddress to = new InternetAddress(e_mail);
    message.addRecipient(Message.RecipientType.TO, to);
    message.setSubject(e_subject[0]);


    if (file_type[0].equals("html")) {

    content_mail ="<font face=\"Verdana\" size=\"2\"> Dear "+e_name+"</font><br>";
    content_mail =content_mail+e_body[0]+"<br><table><tr><td>"+content_file+"</td></tr>";
    content_mail =content_mail+"</table>" ;
    message.setContent(content_mail, "text/html");
    } else {

    content_mail ="Dear "+e_name+" <br>";
    content_mail =content_mail + " <br>" + e_body[0] +" <br>" + content_file +" <br>";
    message.setContent(content_mail, "text/plain");
    }

    try{
    Transport.send(message);
    out.print("<table width=500 border=0 cellspacing=1 cellpadding=0 class=tableText><tr>");
    out.print("<td width=40>" + idx + "</td>");
    out.print("<td width=80>" + e_name + "</td>");
    out.print("<td width=300>" + e_mail + "</td>");
    out.print("<td width=80 align=center>Done</td>");
    out.print("</tr></table>");
    }
    catch(Exception ex){
    ex.printStackTrace();
    }
    idx += 1;
    } //for
    } //try
    catch (Exception exce) {
    // We should really bring up a more specific error dialog here.
    exce.printStackTrace();
    }
    finally { read.close(); }

    } //if


    %>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •