java测试smtp连接失败_java – 在不安装SMTP服务器的情况下测试Gr...

我正在尝试使用Greenmail来测试我的localhost上的电子邮件功能.问题是我没有安装SMTP服务器,并且认为安装一个SMTP服务器过度.我的期望是应该有一个免费的库,允许我保持我的发送邮件代码相同,但不是真正发送电子邮件到SMTP服务器,发送到我的本地机器,以便我可以检索它们(为了单位)测试).

我曾经使用Grails开发时曾使用Greenmail,而且体验很棒.但我找不到类似于Spring Framework的东西.在Greenmail页面中,它说有一个与JBoss捆绑在一起的模拟SMTP服务器.但我不想运行JBoss,因为目前我的Web应用程序正在Tomcat上运行.

Tomcat有没有类似的服务?或者有没有更好的方法将测试电子邮件发送到localhost,我可以在哪里检索发送的电子邮件?

更新:

我尝试使用Ralph的方法,但它仍然产生相同的异常:

[SimpleAsyncTaskExecutor-1] 2012-03-13 10:19:39,475 - ERROR: com.test.my.service.emailing.impl.EmailServiceImpl - Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 3025;

nested exception is:

java.net.ConnectException: Connection refused: connect. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 3025;

nested exception is:

java.net.ConnectException: Connection refused: connect

org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 3025;

nested exception is:

java.net.ConnectException: Connection refused: connect. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 3025;

nested exception is:

java.net.ConnectException: Connection refused: connect; message exception details (1) are:

Failed message 1:

javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 3025;

nested exception is:

java.net.ConnectException: Connection refused: connect

at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1391)

at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)

at javax.mail.Service.connect(Service.java:288)

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.test.my.service.emailing.impl.EmailServiceImpl.test(EmailServiceImpl.java:388)

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:309)

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.interceptor.AsyncExecutionInterceptor$1.call(AsyncExecutionInterceptor.java:80)

at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)

at java.util.concurrent.FutureTask.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

Caused by: java.net.ConnectException: Connection refused: connect

at java.net.PlainSocketImpl.socketConnect(Native Method)

at java.net.PlainSocketImpl.doConnect(Unknown Source)

at java.net.PlainSocketImpl.connectToAddress(Unknown Source)

at java.net.PlainSocketImpl.connect(Unknown Source)

at java.net.SocksSocketImpl.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:233)

at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)

at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1359)

... 19 more

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值