Because my Window's Firewall blocked all outgoing requests on port 587, I had no option but to configure my JavaMailSenderImpl to use SSL instead of TLS. Below are the bean settings.
<beans:bean id="mailSender"
class="org.springframework.mail.javamail.JavaMailSenderImpl">
<beans:property name="username" value="your_mail@gmail.com" />
<beans:property name="password" value="your_mail" />
<beans:property name="protocol" value="smtp"/>
<beans:property name="port" value="465" />
<beans:property name="host" value="smtp.gmail.com" />
<beans:property name="javaMailProperties">
<beans:props>
<beans:prop key="mail.smtp.ssl.enable">true</beans:prop>
<beans:prop key="mail.smtp.auth">true</beans:prop>
<beans:prop
key="mail.smtp.socketFactory.class">javax.net.ssl.SSLSocketFactory</beans:prop>
<beans:prop key="mail.smtp.auth">true</beans:prop>
</beans:props>
</beans:property>
</beans:bean>
@Autowired
@Qualifier("mailSender")
private JavaMailSender javaMailSender;
@Override
public void sendAnmeldung(Message message) throws Exception {
MimeMessage mimemsg = javaMailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimemsg, true);
helper.setTo("your_recipient@gmail.com");
helper.setFrom("your_account@gmail.com");
helper.setText(String.format("Javamail using spring JavaMailSender: %s", Calendar.getInstance().getTime()));
helper.setSubject("test email");
this.javaMailSender.send(mimemsg);
}
The above settings can be used with Spring Integration's out-bound-channel-adapter as follows (of course the prefixes util and int-mail must be bound to their appropriate namespaces properly):
<util:properties id="javaMailProps">
<beans:prop key="mail.smtp.ssl.enable">true</beans:prop>
<beans:prop key="mail.smtp.auth">true</beans:prop>
<beans:prop key="mail.smtp.socketFactory.class">javax.net.ssl.SSLSocketFactory</beans:prop>
<beans:prop key="mail.smtp.auth">true</beans:prop>
</util:properties>
<int-mail:outbound-channel-adapter id="mails"
host="smtp.gmail.com"
java-mail-properties="javaMailProps"
password="your_password"
port="465"
username="your_username@gmail.com"/>
No comments:
Post a Comment