PDA

View Full Version : JavaMailSenderImpl halts when using SSL-secure server?


gro
Aug 26th, 2005, 02:37 AM
Hi, I've been very pleased to work with spring javaMail classes and I got those working for simple non-secure smtp server quite easily. Finally when I started to move the component to production I just tought I'ld add some extra lines to applicationContext and it would work with TSL or SSL enabled server.


<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderIm pl">
<property name="host"><value>mail.server.address</value></property>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
</props>
</property>
<property name="username"><value>username</value></property>
<property name="password"><value>password</value></property>
<property name="port"><value>465</value></property>
<property name="protocol"><value>SSL</value></property>
</bean>


Unfortunately with this configuration it seems to lock when normal mail client is asked to verify server (accept the mac-address as a key). Is there something wrong with my configuration and is there any way to set timeout? At least I get no error messages in any logs.

I also made the MailSender-bean MBean, I connected the bean with Jconsole and tried to form a connection to server. This way I got an error message, unfortunately, the almost nothing of the stacktrace fits into the error box of the Jconsole, but here is what it says:


Problem Invoking dolt: java.rmi.UnmarshalException: Error unmarshaling return; nested exception is:
java.lang.ClassNotFoundException: org.springframework.mail.MailSendException (no security manager: RMI class loader disabled)


I'd be very happy if you could offer me some insight.

roshantitus
Aug 18th, 2006, 05:39 AM
If anybody finds the solution to th above problem please post the details. I am facing the same problem.

haagent
Nov 1st, 2006, 12:58 PM
Here's some tips on connecting to a SMTP mail server using SSL encryption.

First off, you'll need to import the SSL key into a java keystore and tell your Java application or application server (eg., Tomcat) where the keystore file is. We can use OpenSSL to access a server's SSL certificate and save it in a file. Let me point you to some very good documentation provided by JIRA that outlines these steps in detail:

http://confluence.atlassian.com/display/JIRA/Connecting+to+SSL+services

Windows users can get OpenSSL from:

http://www.openssl.org/related/binaries.html

Linux/Unix users probably already have OpenSSL or can get the source at:

http://www.openssl.org

Next, you need to setup JavaMailSenderImpl to use the 'smtps' protocol. Notice that there are two extra properties that must be set and that I have specified a port number. You only need to specify a port number if you are connecting to a non-standard port for a given protocol. Refer to the Spring Framework documentation for examples of sending an email with Spring. That's it!

JavaMailSenderImpl sender = new JavaMailSenderImpl();

Properties mailProps = new Properties();
mailProps.put("mail.smtps.auth", "true");
mailProps.put("mail.smtp.starttls.enable", "true");
sender.setJavaMailProperties(mailProps);

sender.setProtocol("smtps");
sender.setPort(465);
sender.setHost("smtp.myhost.net");
sender.setUsername("myusername");
sender.setPassword("mypassword");

Dosihris
Aug 4th, 2007, 10:28 AM
with the help of this code my exception changed from "Need to authenticate via SMTP first" to "Need to authenticate via POP3 first". Does anybody know the pop3 auth-property?