NutzCN Logo
问答 nutzbook——QQ邮箱发送失败!
发布于 3023天前 作者 老司机 2365 次浏览 复制 上一个帖子 下一个帖子
标签:

dao.js:

conf : {
		type : "org.nutz.ioc.impl.PropertiesProxy",
		fields : {
			paths : [ "custom/" ]
		}
	},

mail.properties:

mail.HostName=smtp.qq.com
mail.SmtpPort=587
mail.UserName=2079947408@qq.com
mail.Password=**********
mail.SSLOnConnect=true
mail.From=2079947408@qq.com
mail.charset=UTF-8

密码为独立密码!
mail.js:

var ioc = {
	emailAuthenticator : {
		type : "org.apache.commons.mail.DefaultAuthenticator",
		args : [ {
			java : "$conf.get('mail.UserName')"
		}, {
			java : "$conf.get('mail.Password')"
		} ]
	},
	htmlEmail : {
		type : "org.apache.commons.mail.ImageHtmlEmail",
		singleton : false,
		fields : {
			hostName : {
				java : "$conf.get('mail.HostName')"
			},
			smtpPort : {
				java : "$conf.get('mail.SmtpPort')"
			},
			authenticator : {
				refer : "emailAuthenticator"
			},
			SSLOnConnect : {
				java : "$conf.get('mail.SSLOnConnect')"
			},
			from : {
				java : "$conf.get('mail.From')"
			},
			charset : {
				java : "$conf.get('mail.charset', 'UTF-8')"
			}
		}
	}
};

MainSetup类的init方法末尾:

 try {
            HtmlEmail email = ioc.get(HtmlEmail.class);
            email.setSubject("测试NutzBook");
            email.setMsg("This is a test mail ... :-)" + System.currentTimeMillis());
            email.addTo("shawn_xiao@supercluster.cn");//请务必改成您自己的邮箱啊!!!
            email.buildMimeMessage();
			email.sendMimeMessage();
        } catch (Exception e) {
            e.printStackTrace();
        }

报错:

org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.qq.com:465
	at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1410)
	at net.wendal.nutzbook.MainSetup.init(MainSetup.java:47)
	at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:276)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:120)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter._init(NutFilter.java:87)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:65)
	at net.wendal.nutzbook.mvc.NutzBookNutFilter.init(NutzBookNutFilter.java:20)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4561)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5203)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1403)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1393)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.qq.com, port: 465;
  nested exception is:
	javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
	at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2055)
	at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:697)
	at javax.mail.Service.connect(Service.java:386)
	at javax.mail.Service.connect(Service.java:245)
	at javax.mail.Service.connect(Service.java:194)
	at javax.mail.Transport.send0(Transport.java:253)
	at javax.mail.Transport.send(Transport.java:124)
	at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1400)
	... 19 more
Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
	at sun.security.ssl.Alerts.getSSLException(Unknown Source)
	at sun.security.ssl.Alerts.getSSLException(Unknown Source)
	at sun.security.ssl.SSLSocketImpl.recvAlert(Unknown Source)
	at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
	at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
	at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
	at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
	at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:543)
	at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:348)
	at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:215)
	at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2019)
	... 26 more

求解惑

13 回复

换163邮箱. QQ邮箱的水太深 -_-

@wendal 那就注明不支持qq邮箱好了……免得后来人不断撞壁(⊙﹏⊙)b

@qq_c1bab051 嗯嗯, 我写的时候是可以的.. 我也纳闷呢...

@wendal 改了mail.properties

mail.HostName=smtp.163.com
mail.SmtpPort=465
mail.UserName=329207595@163.com
mail.Password=********
mail.SSLOnConnect=true
mail.From=329207595@163.com
mail.charset=UTF-8

也不报错直接启动不了

Server Tomcat v9.0 Server at localhost was unable to start within 45 seconds. If the server requires more time, try increasing the timeout in the server editor.

为啥?

杀了重新来.

@wendal 然并卵!虽然邮件可以用其他方法实现!但求大神修改下nutzbook,改成个靠谱的法

不对啊,其他人也能发啊

前后打印一下日志,看看是不是卡在发邮件这一步,还是卡在其他地方了

今早过来直接运行,又OK了,彻底无语(⊙﹏⊙)b

QQ邮箱是可以的,不过要去设置一下 还要发短信什么的

哥们 我的跟你一样了 日了狗

用163或者阿里云邮箱试试吧

添加回复
请先登陆
回到顶部