Hi,
within my stateful session bean i am using the following method, for sending an e-mail:
private void sendMail(String subject, String receiver, String sender,
String content, String mailbox, String password,
String mailServer) {
Password authenticator = new Password(mailbox, password);
Properties sendProps = new Properties();
sendProps.put("mail.smtp.host", mailServer);
session = Session.getInstance(sendProps, authenticator);
try{
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(sender));
InternetAddress[] to = { new InternetAddress(receiver)};
message.setRecipients(Message.RecipientType.TO, to);
message.setSubject(subject);
message.setSentDate(new Date());
message.setText(content);
Transport.send(message);
}catch(MessagingException mex) { mex.printStackTrace(); }
}
but if i try sending i receive the following error:
12:29:28,592 INFO [STDOUT] javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25, response: -1
12:29:28,592 INFO [STDOUT] at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1201)
12:29:28,592 INFO [STDOUT] at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:311)
As you can see, the smtp host is set to localhost - but that is not what i set for the mailServer parameter, when i am calling up the method.
Of course, i can set a resource-reference in the ejb-jar.xml respectively jboss.xml but i want the parameters to be different for each method call.
Does anybody have a solution to this problem?
Thanks for any advices!