sinat_24423367
2016-08-24 08:32
采纳率: 83.3%
浏览 1.2k
已采纳

Javamail stmp邮件问题

  1. 程序完成后,用163邮箱发送邮件没问题,当换成qq邮箱发送时就会出现如下异常:
    2.
    javax.mail.AuthenticationFailedException: failed to connect
    at javax.mail.Service.connect(Service.java:322)
    at javax.mail.Service.connect(Service.java:172)
    at javax.mail.Service.connect(Service.java:121)
    at javax.mail.Transport.send0(Transport.java:190)
    at javax.mail.Transport.send(Transport.java:120)
    at cn.jmail.ssm.utils.mail.MailSender.send(MailSender.java:46)
    at cn.jmail.ssm.controller.SendMail.send(SendMail.java:183)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)

    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:746)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:687)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:822)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)

    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

jsp页面如下:
图片说明

服务器地址是动态切换的:
switch (select) {
case "@qq.com":
SMTP_MAIL_HOST="smtp.qq.com";
break;
case "@163.com":
SMTP_MAIL_HOST="smtp.163.com";

break;
case "@126.com":
SMTP_MAIL_HOST="smtp.126.com";
break;

        **_端口号默认的为25_**
        想知道为什么qq邮箱不能发送邮件?请教各位大神
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

7条回答 默认 最新

  • sinat_24423367 2016-08-25 01:22
    已采纳

    验证了用户名和密码,那就这么用吧

    打赏 评论
  • 羊羊爱代码 2016-08-24 08:44

    看看你的qq有没有开通SMTP发送邮件功能,到qq邮箱中点击设置 -》 账户下面去看看

    打赏 评论
  • paavochan 2016-08-24 08:52

    楼上说的对,最好去看下你的QQ邮箱的配置,有时候没有配置,就不能发送邮件

    打赏 评论
  • sinat_24423367 2016-08-24 08:56

    @羊羊爱代码
    开通了,出错情况还是一样
    图片说明

    打赏 评论
  • 羊羊爱代码 2016-08-24 09:42

    你用继承这个类Authenticator要验证用户名和密码了吗?

    打赏 评论
  • 泰 戈 尔 2016-08-24 22:51

    我当时也遇到了这么个情况,然后就用163了

    打赏 评论
  • qq_22668529 2016-08-29 03:11

    我们前端时间,也是做过这个项目,qq需要授权码作为用户的密码,进行登录发送邮件,把密码换成授权码就可以啦!

    打赏 评论

相关推荐 更多相似问题