dcsimg
class seems to remember TO values across instances
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Michael_Lowden
Posted On:   Thursday, October 11, 2007 04:45 PM

Hello all, I'm trying to figure out why my JavaMail is resending messages to historical TO values. It works perfectly to send the first time after booting Tomcat, but the 2nd and beyond spam the previous TO addresses (as well as CC's) with the current address. I've tried everything i can think of ... including flushing the JavaMail object(s) back to NULL before / after each instance use. Here's my code if anyone has an idea NOTE: it's a Servlet object that calls it. ############# RSVP.java (servlet) ############# private boolean sendEmail() { boolean result[] = {true,true,false}; result[0] = false; // admin result[1] = true; // gue   More>>

Hello all,



I'm trying to figure out why my JavaMail is resending messages to historical TO values. It works perfectly to send the first time after booting Tomcat, but the 2nd and beyond spam the previous TO addresses (as well as CC's) with the current address.



I've tried everything i can think of ... including flushing the JavaMail object(s) back to NULL before / after each instance use.



Here's my code if anyone has an idea

NOTE: it's a Servlet object that calls it.

############# RSVP.java (servlet) #############

			
private boolean sendEmail() {
boolean result[] = {true,true,false};
result[0] = false; // admin
result[1] = true; // guest 1
result[2] = true; // guest 2
try {
PostMail mailer = null;

mailer = new PostMail();
result[1] = (!s_values[5].equals("") && !s_values[3].equals("")) ? mailer.postMail(sFrom, s_values[5], sSubject, sBody) : true;
mailer = null;
mailer = new PostMail();
result[2] = (!s_values[6].equals("") && !s_values[4].equals("")) ? mailer.postMail(sFrom, s_values[6], sSubject, sBody) : true;
mailer = null;

sFrom = "secretEmail@secretDomain.ca";
sSubject = "auto admin update -- "+s_values[3]+(s_values[4].equals("") ? "" : ", "+s_values[4]);
sBody = "BLAH";

mailer = new PostMail();
result[0] = mailer.postMail(sFrom, sTo, sSubject, sBody);
mailer = null;
} catch(Exception e) {
logger.debug( e.getMessage() );
logger.debug( e.getStackTrace().toString() );
} finally {
return (result[0] && result[1] && result[2]);
}
}


############# PostMail.java (regular class) #############
			
package pkg000;

import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.*;
import org.apache.log4j.Logger;

public class PostMail {
private static Logger logger = Logger.getLogger(PostMail.class);

public boolean postMail( String sFrom, String sTo, String sSubject, String sBody ) throws MessagingException {
String sTo2[] = new String[1];
sTo2[0] = sTo;
return postMail(sFrom, sTo2, sSubject, sBody);
}
public boolean postMail( String sFrom, String sTo[], String sSubject, String sBody ) throws MessagingException {
try {
boolean debug = false;

//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", Props.getProp("mail|smtp"));

// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);

// create a sBody
Message msg = new javax.mail.internet.MimeMessage(session);

// set the sFrom and to address
InternetAddress addressFrom = new InternetAddress(sFrom);
msg.setFrom(addressFrom);

InternetAddress[] addressTo = new InternetAddress[sTo.length];
for (int i = 0; i < sTo.length; i++)
addressTo[i] = new InternetAddress(sTo[i]);
msg.setRecipients(Message.RecipientType.TO, addressTo);


// Optional : You can also set your custom headers in the Email if you Want
// msg.addHeader("MyHeaderName", "myHeaderValue");

// Setting the sSubject and Content Type
msg.setSubject(sSubject);
msg.setContent(sBody, "text/html");

Transport.send(msg);
msg = null;
props = null;
session = null;
addressTo = null;
} catch (MessagingException me) {logger.debug("doPOST: " + me.getMessage()); return false;}
return true;
}
}









THANKS IN ADVANCE PEOPLE ... you all rock.
Michael    <<Less
About | Sitemap | Contact