• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaMail application not making use of all the servers behind the smtp smarthost

 
Tony Ignatius
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a Java batch application that sends over 100 emails every run. Our company has got a smtp smarthost behind which there 4 servers. I've configured the smarthost to be our smtp.host.
What we are seeing is when I start my Java job, the first mail get picked by one of the servers, and from then all the emails are servered by the same mail server, not making use of the other 3 servers. Every time it is a different server that picks the mails, but then none of the other servers are being used.
We use the spring's JavaMailSender api to send emails. I tried create new instances on the mailsender before sending the messages but that doesnt seem to help.
Wondering if anyone has faced similar issue before.

Thanks,
Tony
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without seeing your code it's hard to tell whether you are using a single connection (in which case your description would make sense) or whether you are making multiple connections which somehow manage to always hit the same server in the cluster (I'm guessing this product you're describing is a load balancer in front of a collection of servers).
 
Tony Ignatius
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for trying to help.

Our company uses Cisco's IronPort for emails. Not fully sure if it is Load Balancer, but there is some mechanism thats supposed to round-robin the requests (to mailo2) to all the servers.

From the application code perspective, we do not manage connections on our end. The class that sends the mail(I tried attaching the class, but coderanch didnt let me):

public class MessageEmailServiceImpl implements MessageEmailService ,BeanFactoryAware {
private MessageService messageService;
private String from;
private String replyTo;
private int maxRetryCount;
private BeanFactory beanFactory;

public void sendMessage(final Message message, final MemberProgram memberProgram) {
JavaMailSender mailSender=getMailSenderNewInstance();
MimeMessage mimeMessage = mailSender.createMimeMessage();

try {
MimeMessageHelper msgHelper = new MimeMessageHelper(mimeMessage, true);
msgHelper.setTo(memberProgram.getEmailAddress());
msgHelper.setFrom(from);
msgHelper.setReplyTo(replyTo);
msgHelper.setSubject(message.getSubjectLine());
String htmlText = "<html><body><img src='cid:emailLogo'><p>" +
"<span style='font-size: 14px;font-family: Arial'>" + message.getMessageBody() + "</span></body></html>";
msgHelper.setText(htmlText, true);
ClassPathResource resource = new ClassPathResource("emailHeaderLogo.jpg");
msgHelper.addInline("emailLogo", resource);
mailSender.send(mimeMessage);
} catch (Exception sendException) {
String msg = "message [" + message.getId() + "] not sent to member program [" + memberProgram.getId() + "] - " + sendException;
Logger.getLogger(MessageEmailServiceImpl.class).info(msg);

FailedEmailRecipient failedEmailRecipient = new FailedEmailRecipient(message, memberProgram);
messageService.save(failedEmailRecipient);
}
}

public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory= beanFactory;

}
private JavaMailSender getMailSenderNewInstance(){
JavaMailSender mailSender= (JavaMailSender)this.beanFactory.getBean("mailSender");
return mailSender;
}
}


The JavaMailSenderImpl is configured with the smtp host and port.

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl" scope="prototype">
<property name="host" value="mailo2.cname.com"/>
<property name="port" value="25"/>
</bean>

The sendMessage method of the attached MessageEmailServiceImpl gets repeatedly called in a loop for all the messages that are to be sent.

Thanks,
Tony
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So your question boils down to whether getMailSenderNewInstance() returns something which uses a cached JavaMail Session object. Which apparently it does, based on its behaviour.
 
Tony Ignatius
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that is exactly the issue. Do you have any pointers on how to resolve this? I thought creating a new JavaMailSenderImpl instance every-time before the message is sent would resolve the issue. But looks like it didnt help.

Thanks,
Tony
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know anything about the environment in which this code is being run, so I have no idea. For all I know the ultimate source of the mail session is via a JNDI mail session configured into a web application container.
 
Tony Ignatius
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a stand-alone java app kicked nightly as an Autosys task. Is there a way to programmatically clear the JavaMail Session object from the cache?

Thanks,
Tony
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic