The code below works well
But, my question is how can set the ‘javaMailProperties’ programaticaly ?
Because I would like to set ssl/tsl from the code. I could not access these properties, I dont know why, thanks for the solution and explanation.
SimpleMailMessage message=(SimpleMailMessage)SpringUtil.getContext().
getBean("templateMessage");
JavaMailSenderImpl mailSender = (JavaMailSenderImpl)SpringUtil.getContext()
.getBean("mailSender");
mailSender.send(message);
--applicationcontext.xml--
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.gmail.com"/>
<property name="port" value="587"/>
<property name="username" value="your gmail address"/>
<property name="password" value="your password"/>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
</props>
</property>
</bean>
<bean id="templateMessage" class="org.springframework.mail.SimpleMailMessage" >
<property name="from" value="from@gmail.com"/>
<property name="to" value="to@gmail.com"/>
<property name="subject" value="subject"/>
<property name="text" value="hello"/>
</bean>
(I dont want to use javax.mail approach, it was asked)
Use:
Same for other properties that you want to set programatically.
EDIT:
I checked the source code for the
JavaMailSenderImplclass:As you can see, the getJavaMailProperties is a public method and should be available to you. My Spring framework version is 3.0.5.