if you want to deal with bounced mail ...
you have to add your code in RemoteDelivery.java
somewhere along on failMessage()
jaggy
private boolean failMessage(MailImpl mail, MessagingException ex, boolean permanent) {
StringWriter sout = new StringWriter();
PrintWriter out = new PrintWriter(sout, true);
if (permanent) {
out.print("Permanent");
} else {
out.print("Temporary");
}
StringBuffer logBuffer =
new StringBuffer(64)
.append(" exception delivering mail (")
.append(mail.getName())
.append(": ");
out.print(logBuffer.toString());
ex.printStackTrace(out);
log(sout.toString());
if (!permanent) {
if (!mail.getState().equals(Mail.ERROR)) {
mail.setState(Mail.ERROR);
mail.setErrorMessage("0");
mail.setLastUpdated(new Date());
}
int retries = Integer.parseInt(mail.getErrorMessage());
if (retries < maxRetries) {
logBuffer =
new StringBuffer(128)
.append("Storing message ")
.append(mail.getName())
.append(" into outgoing after ")
.append(retries)
.append(" retries");
log(logBuffer.toString());
++retries;
mail.setErrorMessage(retries + "");
mail.setLastUpdated(new Date());
return false;
} else {
logBuffer =
new StringBuffer(128)
.append("Bouncing message ")
.append(mail.getName())
.append(" after ")
.append(retries)
.append(" retries");
log(logBuffer.toString());
}
}
// any bounced related add-ons should be added here
// below this line is the sample code to log bouncemail in reply-to,recepient,subject
format per line
MimeMessage mm = null;
String subj = null;
String errorTo = null;
try {
mm = mail.getMessage();
subj = mm.getSubject();
}
catch (MessagingException e) {
System.out.println(e.getMessage());
}
for (Iterator i = mail.getRecipients().iterator(); i.hasNext();) {
StringBuffer lbf = new StringBuffer(128)
.append(mail.getSender())
.append(",")
.append(i.next())
.append(",")
.append(subj);
Date mydate = new Date();
SimpleDateFormat formatter;
formatter = new SimpleDateFormat("MM-dd-yyyy");
try {
FileWriter daWriter = new FileWriter("C:/BOUNCEDMAIL/bounced_" +
formatter.format(mydate).toString() + ".log", true);
daWriter.write(lbf.toString() + "\r\n");
daWriter.close();
}
catch (IOException e) {
e.printStackTrace();
}
out.println(i.next());
}
subj = null;
errorTo = null;
bounce(mail, ex);
return true;
}
-----Original Message-----
From: Alagan Sathianathan [mailto:[EMAIL PROTECTED]
Sent: Monday, April 05, 2004 12:16 PM
To: [EMAIL PROTECTED]
Subject: James to manage the bounced emails
I am using James to hadnle the bounced emails. When ever there is a bounced mail
from, it will be forwared to my James Server. I am running a thrad process to look at
the bounced mails and forward the mails to some admin and delete the messages.
But I have problems in deleting the messages.Geting
"javax.mail.MethodNotSupportedException: Expunge not supported
" . Here id the code:
//
public void process() {
try {
Message msgs[] = getMessages();
if( msgs != null){
log.info("Processing "+msgs.length+" Messages");
}
if (msgs != null)
for (int i = 0; i < msgs.length; i++) {
if (!wasProcessed(msgs[i])) {
msg[i].setFlag(Flags.Flag.DELETED,
true); }
}
// Notify REPLYTO Address
// TODO to be implemented
// delete them from inbox HAVING PROBELM HERE
folder.expunge();
} catch (Exception e) {
// TODO: handle exception
log.warn("Exception thrown");
}
}
//
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]