javamail + EXIM -- repeated mails

B

Bart Ogryczak

Hi,
I'm trying to send a quiet a few mails using multithreaded aplication,
sending to various outgoing SMTP servers (EXIM). Some of those mails
get resent after exactly 3600s, with different MsgID. How can I avoid
that?

bart
 
D

Dave Miller

Bart said:
Hi,
I'm trying to send a quiet a few mails using multithreaded aplication,
sending to various outgoing SMTP servers (EXIM). Some of those mails
get resent after exactly 3600s, with different MsgID. How can I avoid
that?

bart
For troubleshooting help, please post your code.
 
B

Bart Ogryczak

For troubleshooting help, please post your code.


public class MailSender implements Runnable {
private BlockingQueue<Map> queue;
Session mailSession;
/*... more stuff related to generation of content...*/

public MailSender(BlockingQueue<Map> queue, String smtp) {
this.queue = queue;
if(smtp.contains(":")) {
String[] smtpSplit = smtp.split(":");
smtpHost = smtpSplit[0];
smtpPort = Integer.parseInt(smtpSplit[1]);
} else {
smtpHost = smtp;
smtpPort = 25;
}
}

public void run() {
try {
while(true) {
Map t = queue.take(); //content data
if(t.containsKey(this.config.getString("POISON"))) break;
try {
Properties props = new Properties();
props.put("mail.smtp.allow8bitmime", "true");
props.put("mail.smtp.host", smtpHost);
props.put("mail.smtp.port", ""+smtpPort );
props.put("mail.smtp.from", "(e-mail address removed)" );
props.put("mail.from", "(e-mail address removed)" );
mailSession = Session.getInstance(props);

SimpleEmail email = new SimpleEmail(); /* from apache.commons.mail */
email.setMailSession(mailSession);
email.setFrom("my@from");
email.addTo(t.get("email")+"");
email.setSubject("my subject");
email.setCharset("UTF-8");
String html = contentGenerator.getContent(t);
email.setContent(html,"text/html");
try {
email.send();
} catch (Exception e) {
System.out.println("send failed "+t);
e.printStackTrace(System.out);
}
} catch (Exception e) {
System.out.println("failed processing "+t);
e.printStackTrace(System.out);
}
}

} catch(InterruptedException e) {}
System.out.println("terminated");
} //end run
} //end class


In the main app, I create 50 threads sending to 8 SMTP servers.

taskQueue = new LinkedBlockingQueue<Map>(config.getInt("TASK_QUEUE"));
String[] smtp = config.getStringArray("SMTP_SERVERS");
Collections.shuffle(Arrays.asList(smtp));

for(int i=0;i<nThrsTasks;i++) {
new Thread(new MailSender(taskQueue,smtp[i%smtp.length])).start();
}


bart
 
D

Dave Miller

Bart said:
For troubleshooting help, please post your code.


public class MailSender implements Runnable {
private BlockingQueue<Map> queue;
Session mailSession;
/*... more stuff related to generation of content...*/

public MailSender(BlockingQueue<Map> queue, String smtp) {
this.queue = queue;
if(smtp.contains(":")) {
String[] smtpSplit = smtp.split(":");
smtpHost = smtpSplit[0];
smtpPort = Integer.parseInt(smtpSplit[1]);
} else {
smtpHost = smtp;
smtpPort = 25;
}
}

public void run() {
try {
while(true) {
Map t = queue.take(); //content data
if(t.containsKey(this.config.getString("POISON"))) break;
try {
Properties props = new Properties();
props.put("mail.smtp.allow8bitmime", "true");
props.put("mail.smtp.host", smtpHost);
props.put("mail.smtp.port", ""+smtpPort );
props.put("mail.smtp.from", "(e-mail address removed)" );
props.put("mail.from", "(e-mail address removed)" );
mailSession = Session.getInstance(props);

SimpleEmail email = new SimpleEmail(); /* from apache.commons.mail */
email.setMailSession(mailSession);
email.setFrom("my@from");
email.addTo(t.get("email")+"");
email.setSubject("my subject");
email.setCharset("UTF-8");
String html = contentGenerator.getContent(t);
email.setContent(html,"text/html");
try {
email.send();
} catch (Exception e) {
System.out.println("send failed "+t);
e.printStackTrace(System.out);
}
} catch (Exception e) {
System.out.println("failed processing "+t);
e.printStackTrace(System.out);
}
}

} catch(InterruptedException e) {}
System.out.println("terminated");
} //end run
} //end class


In the main app, I create 50 threads sending to 8 SMTP servers.

taskQueue = new LinkedBlockingQueue<Map>(config.getInt("TASK_QUEUE"));
String[] smtp = config.getStringArray("SMTP_SERVERS");
Collections.shuffle(Arrays.asList(smtp));

for(int i=0;i<nThrsTasks;i++) {
new Thread(new MailSender(taskQueue,smtp[i%smtp.length])).start();
}


bart
Sorry that I can't be of more help. The "exactly 3600s" (1 hour) says
it's a retry by Exim. Why the message is being successfully sent and
also placed in one of the Exim's failed queue is, I think, the question.
The only thing that I can think to try is to find the messages in the
Exim retry queue(s) and try to backtrack those messages.
 
N

Nigel Wade

Bart said:
Hi,
I'm trying to send a quiet a few mails using multithreaded aplication,
sending to various outgoing SMTP servers (EXIM). Some of those mails
get resent after exactly 3600s, with different MsgID. How can I avoid
that?

bart

Presumably the Exim server encountered a temporary delivery problem and
re-queued the email. Check the Exim log. If the remote SMTP server to which
Exim was trying to deliver reported a temporary problem (a 4XX response) then
Exim would queue the message and retry later.

This isn't a Java problem, though. It's the normal operation for SMTP between
MTA's. If the message has been successfully accepted by Exim then your Java has
done its job. Exim will then do its job and deliver the mail to its final
destination, or will bounce the message if the retry limit expires (typically 3
days) or an error occurs.
 
B

Bart Ogryczak

Bart said:
Hi,
I'm trying to send a quiet a few mails using multithreaded aplication,
sending to various outgoing SMTP servers (EXIM). Some of those mails
get resent after exactly 3600s, with different MsgID. How can I avoid
that?
[...]
This isn't a Java problem, though. It's the normal operation for SMTP between
MTA's. If the message has been successfully accepted by Exim then your Java has
done its job.

It seems that's something like JavaMail doesn't get "200 OK" response from
Exim, probably doesn't get any response at all, and connection gets closed
becouse of timeout. Having no response at all JavaMail (or Transport) sends
the mail again. Is there any property I could set, to prevent that?
I'm positive that it is JavaMail problem, those mails have distinct MsgIDs.

Other question. Is JavaMail thread-safe? It seems to me, that even though
I create new Session objects with Session.getInstance(props) for every thread,
they share properties (SMTP server).

bart
 
D

Dave Miller

Bart said:
Bart said:
Hi,
I'm trying to send a quiet a few mails using multithreaded aplication,
sending to various outgoing SMTP servers (EXIM). Some of those mails
get resent after exactly 3600s, with different MsgID. How can I avoid
that?
[...]
This isn't a Java problem, though. It's the normal operation for SMTP between
MTA's. If the message has been successfully accepted by Exim then your Java has
done its job.

It seems that's something like JavaMail doesn't get "200 OK" response from
Exim, probably doesn't get any response at all, and connection gets closed
becouse of timeout. Having no response at all JavaMail (or Transport) sends
the mail again.

On its own, JavaMail does nothing other than take your message,
transport it to the MTA and return any messages from the MTA. Is your
program still running after an hour (3600s)? If so, log its output and
use that to troubleshoot. If not, it must be Exim - read the logs and
/or check the queues in real time.

Is there any property I could set, to prevent that?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top