e ai pessoal blz,
consegui evoluir um pouco com o Spring, porem ainda estou com problemas.
quero enviar um e-mail usando o Spring, estou fazendo assim:
dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:sa="http://sannotations.sourceforge.net/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://sannotations.sourceforge.net/context http://sannotations.sourceforge.net/context.xsd"
default-autowire="byName">
<import resource="classpath*:applicationContext.xml" />
<sa:annotation-autoload />
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<bean id="viewNameTranslator"
class="org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator" />
<bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath" value="/" />
<!--property name="configLocation" value="WEB-INF/velocity.properties" /-->
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver" >
<property name="prefix" value="pages/" />
<property name="suffix" value=".vm" />
<property name="toolboxConfigLocation" value="WEB-INF/toolbox.xml" />
</bean>
<bean id="confirmacao"
class="br.com.exemplo.web.Usuario.ConfirmacaoController">
<property name="mailSender"><ref bean="mailSender"/></property>
<property name="message"><ref bean="message"/></property>
</bean>
<bean id="mailSender"
class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="javaMailProperties">
<props>
<prop key="mail.MailTransport.protocol">smtp</prop>
<prop key="mail.smtp.host">smtp.gmail.com</prop>
<prop key="mail.smtp.port">465</prop>
<prop key="mail.smtp.user">rafaelhornung@gmail.com</prop>
<prop key="mail.smtp.password">senha(</prop>
<prop key="mail.smtp.auth">true</prop>
</props>
</property>
</bean>
<bean id="message" class="org.springframework.mail.SimpleMailMessage">
<property name="from" value="rafaelhornung@gmail.com"/>
<property name="subject" value="Exemplo"/>
</bean>
</beans>
ConfirmacaoController.java
package br.com.exemplo.web.Usuario;
import javax.mail.MessagingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.mail.MailException;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import java.security.Security;
public class ConfirmacaoController implements Controller {
private MailSender mailSender;
private SimpleMailMessage message;
public void setMailSender(MailSender mailSender) {
this.mailSender = mailSender;
}
public void setMessage(SimpleMailMessage message) {
this.message = message;
}
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws MessagingException {
boolean confirmacaoEmail = false;
String recipients = "rafaelhornung@gmail.com";
String message = ""+
" <b>Para ativar a sua conta acesse o endereço abaixo:</b>"+
" <br /><br />"+
" <a href='http://127.0.0.1:8080/exemplo/ativacao.htm'>" +
" http://127.0.0.1:8080/exemplo/ativacao.htm" +
" </a>"+
" <br /><br />"+
" <b>Seja bem vindo!</b>"+
"";
confirmacaoEmail = enviaEmail(recipients, message);
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
if(confirmacaoEmail){
return new ModelAndView("usuario/cadastro_confirmacao");
}else{
return new ModelAndView("usuario/cadastro_confirmacao_erro");
}
}
public boolean enviaEmail(String to, String msg){
SimpleMailMessage simpleMailMessage = new SimpleMailMessage(this.message);
simpleMailMessage.setTo(to);
simpleMailMessage.setText(msg);
try{
this.mailSender.send(simpleMailMessage);
return true;
}
catch(MailException ex) {
System.err.println(ex.getMessage());
return false;
}
}
}
quando executo aparece o seguinte erro no eclipse:
Página: /confirmacao.htm Contexto: /exemplo
Authentication failed; nested exception is javax.mail.AuthenticationFailedException
alguem sabe como posso arrumar isso?
Rafael Hornung