日期:2014-05-20  浏览次数:20750 次

spring发送邮件出错
Java code

// 发送注册邮件开始
        JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
        javaMailSender.setHost("smtp.sohu.com");
        Properties pro = new Properties();
        pro.setProperty("mail.smtp.auth","true");
        javaMailSender.setJavaMailProperties(pro);
        javaMailSender.setUsername("xxx@sohu.com");
        javaMailSender.setPassword("123456");
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage,
                true, "utf-8");
        messageHelper.setFrom("xxx@sohu.com");
        messageHelper.setTo(email);
        messageHelper.setSubject("修改密码邮件!");
        String content = "<html><head><title>修改密码邮件</title></head><body>"
                + "<p>尊敬的用户,您的新密码为:</p>"
                + randomPassword
                +"<p>请及时修改!</p></body></html>";
        messageHelper.setText(content, true); // 邮件正文
        javaMailSender.send(mimeMessage);
        // 发送注册邮件结束


执行到javaMailSender.send(mimeMessage);就报错
org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException
[15:24:47.678] {http--8080-2$13326029} org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException
[15:24:47.678] {http--8080-2$13326029} at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:416)
[15:24:47.678] {http--8080-2$13326029} at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:342)
[15:24:47.678] {http--8080-2$13326029} at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:338)
[15:24:47.678] {http--8080-2$13326029} at _jsp._getpassdo__jsp._jspService(_getpassdo__jsp.java:113)
[15:24:47.678] {http--8080-2$13326029} at com.caucho.jsp.JavaPage.service(JavaPage.java:61)
[15:24:47.678] {http--8080-2$13326029} at com.caucho.jsp.Page.pageservice(Page.java:578)
[15:24:47.678] {http--8080-2$13326029} at com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:195)
[15:24:47.678] {http--8080-2$13326029} at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
[15:24:47.678] {http--8080-2$13326029} at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
[15:24:47.678] {http--8080-2$13326029} at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:87)
[15:24:47.678] {http--8080-2$13326029} at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:112)
[15:24:47.678] {http--8080-2$13326029} at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
[15:24:47.678] {http--8080-2$13326029} at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:87)
[15:24:47.678] {http--8080-2$13326029} at cet.util.EnvFilter.doFilter(EnvFilter.java:38)
[15:24:47.678] {http--8080-2$13326029} at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:87)
[15:24:47.678] {http--8080-2$13326029} at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:187)
[15:24:47.678] {http--8080-2$13326029} at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:265)
[15:24:47.678] {http--8080-2$13326029} at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:273)
[15:24:47.678] {http--8080-2$13326029} at com.caucho.server.port.TcpConnection.run(TcpConnection.java:682)