我在本地试过163,126,sina的SMTP,都报Could not connect to SMTP host,java.net.SocketException: Permission denied: connect,我记得以前用同样的代码发送成功过的。不知道现在为什么不可以
代码:spring配置文件
<bean id="freeMarkerConfigurer" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean"> <property name="templateLoaderPath" value="/WEB-INF/ftl/emailTemplate/" /> <property name="freemarkerSettings"><!-- 设置FreeMarker环境属性 --> <props> <prop key="default_encoding">UTF-8</prop><!--模板的编码格式 --> <prop key="locale">zh_CN</prop><!-- 本地化设置 --> <prop key="template_update_delay">1800</prop><!--刷新模板的周期,单位为秒--> </props> </property> <property name="freemarkerVariables"> <map> <entry key="webRoot" value="${webRoot}" /> </map> </property> </bean> <!--异步线程执行器--> <bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"> <property name="corePoolSize" value="10"/> <property name="maxPoolSize" value="30"/> </bean> <!--邮件 注意:这里的参数(如用户名、密码)都是针对邮件发送者的 --> <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> <property name="host"> <value>${SMTPHOST}</value> </property> <property name="port"> <value>${SMTPPORT}</value> </property> <property name="javaMailProperties"> <props> <prop key="mail.smtp.auth">true</prop> <prop key="mail.smtp.timeout">25000</prop> </props> </property> <property name="username"> <value>${SMTPUSER}</value> </property> <property name="password"> <value>${SMTPPASS}</value> </property> </bean>
JAVA 代码:
public void sendEmail(String userName, String title, String content, String address, String tempName) { super.subject = title; MimeMessage msg = sender.createMimeMessage(); MimeMessageHelper helper; try { helper = new MimeMessageHelper(msg, true, "utf-8"); helper.setTo(address); // 邮件接收地址 try { helper.setFrom(new InternetAddress(getFrom(), "test")); } catch (UnsupportedEncodingException e) { log.error("sendEmail", e); e.printStackTrace(); } helper.setSubject(title); // 主题 String htmlText = getMailText(userName, address, content, tempName); // 使用模板生成html邮件内容 helper.setText(htmlText, true); sender.send(msg); // 发送邮件 } catch (MessagingException e) { log.error("sendEmail", e); e.printStackTrace(); } }
telnet smtp时提示:
220 irxd5-203.sinamail.sina.com.cn ESMTP
错误如下:
org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: smtp.sina.com, port: 25; nested exception is: java.net.SocketException: Permission denied: connect. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: smtp.sina.com, port: 25; nested exception is: java.net.SocketException: Permission denied: connect; message exception details (1) are: Failed message 1: javax.mail.MessagingException: Could not connect to SMTP host: smtp.sina.com, port: 25; nested exception is: java.net.SocketException: Permission denied: connect at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:911) at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:158) at javax.mail.Service.connect(Service.java:233) at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:389) at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:340) at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:336) at com.thinkdee.mail.impl.EmailServiceImpl.sendEmail(EmailServiceImpl.java:71) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at com.sun.proxy.$Proxy17.sendEmail(Unknown Source) at com.thinkdee.action.IndexController.regUser(IndexController.java:80) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:439) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:427) 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:637) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61) at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383) at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 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:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454) at java.lang.Thread.run(Unknown Source)
相关推荐
3、Can’t connect to local MySQL server through socket ‘/Data/mydata/mysql.sock’ socket文件目录不对应导致的问题 4、今天要说的就是 没有打开only_full_group_by Cause:...
javax.mail.MessagingException: Could not connect to SMTP host: zxkaka.com, port: 25; 出现这个问题时,我在foxmail 以及 outlook都可以发送邮件的。 免得自己以后忘记,在源码里注释写的很清楚
错误: 代理抛出异常错误: java.rmi.server.ExportException: Port already in use: 1099; nested exception is: java.net.BindException: Address already in use: JVM_Bind 这里说的是1099端口被其它进程占用...
然而,当你遇到“javax.net.ssl.SSLException: java.lang.RuntimeException: Could not generate DH keypair”的错误时,这意味着在建立SSL/TLS连接时,Diffie-Hellman(DH)密钥交换算法遇到了问题。DH是一种非对称...
然而,当出现"HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError)"这样的错误时,意味着在序列化过程中遇到了无限递归的问题。这个问题通常是由于对象之间的引用循环...
接下来,`Nested`文件可能包含了具体的Java代码,这些代码展示了如何在Spring应用中设置和使用Nested事务。通常,Spring的`PlatformTransactionManager`接口是处理事务的核心,而`@Transactional`注解则用于声明方法...
- FIX: The TFlexPanel.FindControlAtPoint method maked virtual to realize RealTime-capability when on mouse cursor moving the flex-object search not occurs. - FIX: After deleting the selected points ...
之前tomcat启动老是报错,虽然不影响项目的启动运行,但是有强迫症的程序员会心里不爽: 如下: 问题分析 由于本机安装的jdk版本与tomcat中使用的jdk版本不一致导致的。 解决方法 后面我把原先tomcat启动环境用的...
<groupId>com.squareup.okio</groupId> <artifactId>okio <version>2.8.0</version>
2013-08-12 14:33:37.672:WARN::Nested in org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in URL [file:/E:/cloudwave-core/src/main/...
dm_jdbc\com.dameng.floader.jar dm_jdbc\com.dameng.impexp.jar dm_jdbc\Dm7Dictionary.jar dm_jdbc\Dm7JdbcDriver14.jar dm_jdbc\Dm7JdbcDriver15.jar dm_jdbc\Dm7JdbcDriver16.jar dm_jdbc\Dm7JdbcDriver17.jar ...
你可以通过条件判断或者使用`Build.VERSION.SDK_INT`来检查当前设备的API级别,只在API Level 21及以上的设备上使用`PersistableBundle`。 ```java if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ...
nested exception is org.hibernate.PropertyNotFoundException: Could not find a getter for ID in class ``` 这表示Hibernate找不到实体类中的 ID 属性的 getter 方法。 **解决方法**: 1. **实体类定义**:...
Java程序在运行过程中可能会遇到各种异常,其中"nested exception is java.lang.OutOfMemoryError: Java heap space"是一个常见的问题,通常发生在程序试图分配超过堆内存限制的空间时。这个错误表明Java虚拟机(JVM...
在使用Mybatis框架时,你可能会遇到`org.apache.ibatis.exceptions.PersistenceException`这样的异常。这个异常通常表示在执行数据库查询操作时遇到了问题。本篇将详细分析这个问题并提供解决方法。 ### 问题概述 ...
nested exception is java.lang.AbstractMethodError: org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator.postProcessAfterInstantiation(Ljava/lang/Object;Ljava/lang/String;)Z at org....
2. 使用`java.lang.ClassLoader.loadLibrary()`代替`System.loadLibrary()`,这样可以提供更精确的库文件路径。 3. 检查是否有其他依赖库冲突,有时多个库可能使用相同的名字,导致加载混乱。 最后,博客链接<https...
- 使用JVM工具如VisualVM、JConsole等监控应用程序的内存使用情况。 - 分析堆转储文件(heap dump),找出占用内存较大的对象集合。 **注意事项:** - 调整JVM参数时需谨慎,过大的堆可能会导致其他问题,如GC停顿...