I am trying to send mail using apache james server. I have done with all james configuration.
My code executes correctly there is no exception. But mail could not deliver.
Here is my sample code
public void sendMail(String toField, String subject, Users user,
HttpServletRequest request)throws Exception {
// TODO Auto-generated method stub
logger.info("sending mail....");
String loginLink = request.getScheme() +"://" + request.getServerName()
+ ":" + request.getServerPort() + request.getContextPath()+"/auth/login";
// Prepare the evaluation context
final WebContext ctx = new WebContext(request, request.getSession()
.getServletContext(),request.getLocale());
ctx.setVariable("eagletId", user.getEagletId());
ctx.setVariable("name", user.getFirstName());
ctx.setVariable("setSentDate", new Date());
ctx.setVariable("password", user.getPassword());
ctx.setVariable("link",loginLink);
// Create a mail session
Properties properties = new Properties();
properties.put("mail.smtp.host", "localhost");
properties.put("mail.smtp.port", "25");
properties.put("mail.smtp.username", "coepleap");
properties.put("mail.smtp.password", "coepleap");
Session session = Session.getDefaultInstance(properties,new Authenticator() {
protected PasswordAuthentication getpassAuthentication(){
return new PasswordAuthentication("coepleap", "coepleap");
}
});
MimeMessage message = new MimeMessage(session);
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
message.setFrom(new InternetAddress("coepleap"));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(toField));
helper.setSubject(subject);
final String htmlContent = this.templateEngine.process("email.html",ctx);
helper.setText(htmlContent,true);
Transport.send(message);
}
}
anyone who can help me out?