NutzCN Logo
问答 Sending the email to the following server failed : smtp.aliyun.com:25
发布于 2157天前 作者 mozhaojian 2781 次浏览 复制 上一个帖子 下一个帖子
标签:

今天在看Wendal大哥的进阶手册,在做邮箱验证板块测试发送邮件的第一步就出错了,具体错误如下:

org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.aliyun.com:25
	at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1410)
	at net.wendal.nutzbook.MainSetup.init(MainSetup.java:50)
	at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:278)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:121)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter._init(NutFilter.java:91)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:69)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:285)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:266)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4637)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5282)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1420)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1410)
	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)

使用的配置文件呢,是从wendal大哥那里复制过来的,mail.properties:

mail.HostName=smtp.aliyun.com
mail.SmtpPort=25
mail.UserName=wendal3@aliyun.com
mail.Password=book@2015
mail.SSLOnConnect=false
mail.From=wendal3@aliyun.com
mail.charset=UTF-8

MainSetup的代码是这样子的:

package net.wendal.nutzbook;

import java.util.Date;

import org.apache.commons.mail.HtmlEmail;
import org.nutz.dao.Dao;
import org.nutz.dao.util.Daos;
import org.nutz.integration.quartz.NutQuartzCronJobFactory;
import org.nutz.ioc.Ioc;
import org.nutz.mvc.NutConfig;
import org.nutz.mvc.Setup;

import net.wendal.nutzbook.bean.User;

/**
 * MainSetup需要实现Setup接口,并在其中初始化数据库表
 * @author chris
 *
 */
public class MainSetup implements Setup{
	
	@Override
	public void init(NutConfig nc) {
			Ioc ioc = nc.getIoc();
			Dao dao = ioc.get(Dao.class);
			//// 如果没有createTablesInPackage,请检查nutz版本
			Daos.createTablesInPackage(dao, "net.wendal.nutzbook", false);
			
			
			//初始化默认根用户
			if (dao.count(User.class) == 0) {
				User user = new User();
				user.setName("admin");
				user.setPassword("123456");
				user.setCreateTime(new Date());
				user.setUpdateTime(new Date());
				dao.insert(user);
			}
			
			 // 获取NutQuartzCronJobFactory从而触发计划任务的初始化与启动
	        ioc.get(NutQuartzCronJobFactory.class);
	        
	     // 测试发送邮件
	        try {
	            HtmlEmail email = ioc.get(HtmlEmail.class);
	            email.setSubject("测试NutzBook");
	            email.setMsg("This is a test mail ... :-)" + System.currentTimeMillis());
	            email.addTo("452924167@qq.com");//请务必改成您自己的邮箱啊!!!
	            email.buildMimeMessage();
	            email.sendMimeMessage();
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	        
	        
	}
	
	@Override
	public void destroy(NutConfig nc) {
		// webapp销毁之前执行的逻辑
        // 这个时候依然可以从nc取出ioc, 然后取出需要的ioc 对象进行操作
	}

}

好了,信心满满的启动服务器,结果就报了上面的错误了。这个时候我百度了一下,发现阿里云邮箱的mail.SmtpPort=25端口早就被停用了,大家都用465端口了,于是我把mail.SmtpPort改为465,一启动服务器还是报错:

org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.aliyun.com:465
	at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1410)
	at net.wendal.nutzbook.MainSetup.init(MainSetup.java:50)
	at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:278)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:121)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter._init(NutFilter.java:91)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:69)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:285)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:266)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4637)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5282)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1420)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1410)
	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)

什么!!!!

这时侯我想起了wendal大哥的原话是:

注意,上述账号只是测试用的,密码随时更改,请使用您自己的QQ邮箱信息及服务器地址

那就换个我自己的邮箱,用qq邮箱好像有点low,于是我改用163邮箱,修改后的配置文件如下:

mail.HostName=smtp.163.com
mail.SmtpPort=25
mail.UserName=邮箱名@163.com
mail.Password=邮箱密码
mail.SSLOnConnect=false
mail.From=邮箱名@163.com
mail.charset=UTF-8

然后启动服务器就成功了,163邮箱的25端口没被禁用!

注意:自己的邮箱一定要开启SMTP服务,不然还是会报error的

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