how2j.cn

下载区
文件名 文件大小
hutool.rar 129k
使用站长秘制下载工具
步骤 1 : TestMail   
步骤 2 : pom.xml   
步骤 3 : qq邮箱   
步骤 4 : 可运行项目   

经过测试,是可以发送出去的。但是需要自己申请邮箱。 最好用 163的邮箱,没那么多问题,qq邮箱,foxmail,什么的都会出现奇奇怪怪的问题,不好调试。
TestMail
package cn.how2j.test; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import java.lang.annotation.Documented; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.lang.reflect.Method; import org.junit.Before; import org.junit.Test; import cn.hutool.core.convert.Convert; import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.extra.mail.MailAccount; import cn.hutool.extra.mail.MailUtil; public class TestMail { private MailAccount account; @Before public void prepareMailAccount() { account = new MailAccount(); account.setHost("smtp.163.com"); account.setPort(25); account.setAuth(true); account.setFrom("test@163.com"); //假邮箱,请自己申请真实邮箱 account.setUser("test@163.com"); //假邮箱,请自己申请真实邮箱 account.setPass("testpassword"); //假密码,请自己申请真实邮箱 } @Test @Comment("发送普通文本") public void test1(){ //因为账号密码不对,所以不能正确发送 //MailUtil.send(account,"test@163.com", "hutool 测试邮件" + DateUtil.now(), "测试内容", false); } @Test @Comment("发送html邮件") public void test2(){ //因为账号密码不对,所以不能正确发送 //MailUtil.send(account,"test@163.com", "hutool 测试邮件" + DateUtil.now(), "<p>测试内容</p>", true); } @Test @Comment("发送带附件的邮件") public void test3(){ //因为账号密码不对,所以不能正确发送 MailUtil.send(account,"test@163.com", "hutool 测试邮件" + DateUtil.now(), "<p>测试内容</p>", true, FileUtil.file("d:/test.txt")); } private String preComment = null; private void c(String msg) { System.out.printf("\t备注:%s%n",msg); } private void p1(String type1, Object value1, String type2, Object value2) { p(type1, value1, type2, value2, "format1"); } private void p2(String type1, Object value1, String type2, Object value2) { p(type1, value1, type2, value2, "format2"); } private void p3(String type1, Object value1) { p(type1, value1, "", "", "format3"); } private void p(String type1, Object value1, String type2, Object value2, String format) { try { throw new Exception(); } catch (Exception e) { String methodName = getTestMethodName(e.getStackTrace()); Method m =ReflectUtil.getMethod(this.getClass(), methodName); Comment annotation = m.getAnnotation(Comment.class); if(null!=annotation) { String comment= annotation.value(); if(!comment.equals(preComment)) { System.out.printf("%n%s 例子: %n%n",comment); preComment = comment; } } } int padLength = 12; type1=StrUtil.padEnd(type1,padLength,Convert.toSBC(" ").charAt(0)); type2=StrUtil.padEnd(type2,padLength,Convert.toSBC(" ").charAt(0)); if("format1".equals(format)) { System.out.printf("\t%s的:\t\"%s\" %n\t被转换为----->%n\t%s的 :\t\"%s\" %n%n",type1,value1, type2, value2); } if("format2".equals(format)) { System.out.printf("\t基于 %s:\t\"%s\" %n\t获取 %s:\t\"%s\"%n%n",type1,value1, type2, value2); } if("format3".equals(format)) { System.out.printf("\t%s:\t\"%s\" %n\t%n",type1,value1); } } private String getTestMethodName(StackTraceElement[] stackTrace) { for (StackTraceElement se : stackTrace) { String methodName = se.getMethodName(); if(methodName.startsWith("test")) return methodName; } return null; } @Target({METHOD,TYPE}) @Retention(RetentionPolicy.RUNTIME) @Inherited @Documented public @interface Comment { String value(); } }
从现在开始,都是需要第三方包 才能使用的 hutool 功能了
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>cn.how2j</groupId> <artifactId>hutool</artifactId> <version>0.0.1-SNAPSHOT</version> <name>hutool</name> <description>hutool</description> <dependencies> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>4.3.1</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.3.1</version> <scope>test</scope> </dependency> <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>1.4.7</version> </dependency> </dependencies> </project>
关于qq邮箱如果要使用,密码要使用授权码。 授权码的获取手段:
https://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256
在右上角有本知识点对应的可运行项目下载 ,实在自己搞不出来,就下载解压出来比较一下。


HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。


问答区域    
2019-08-02 发送报异常:Could not connect to SMTP host: smtp.163.com, port: 25, response: 554
小苏



添加自己163邮箱账号密码,发送的163邮箱。发送失败
package com.unicom.st.stweb.happaystudyactivity.coursestudy.controller;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import java.lang.annotation.Documented;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
import org.junit.Before;
import org.junit.Test;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;

public class TestMail {
    private MailAccount account;

    @Before
    public void prepareMailAccount() {
        account = new MailAccount();
        account.setHost("smtp.163.com");
        account.setPort(25);
        account.setAuth(true);
        account.setFrom("toyouu@163.com"); //假邮箱,请自己申请真实邮箱
        account.setUser("toyouu@163.com"); //假邮箱,请自己申请真实邮箱
        account.setPass("..已填.."); //假密码,请自己申请真实邮箱
    }

    @Test
    @Comment("发送普通文本")
    public void test1(){
        //因为账号密码不对,所以不能正确发送
        //MailUtil.send(account,"test@163.com", "hutool 测试邮件" + DateUtil.now(), "测试内容", false);
    }
    @Test
    @Comment("发送html邮件")
    public void test2(){
        //因为账号密码不对,所以不能正确发送
        MailUtil.send(account,"toyouu8@163.com", "hutool 测试邮件" + DateUtil.now(), "<p>测试内容</p>", true);
    }
    @Test
    @Comment("发送带附件的邮件")
    public void test3(){

        //因为账号密码不对,所以不能正确发送
        MailUtil.send(account,"toyouu8@163.com", "hutool 测试邮件" + DateUtil.now(), "<p>测试内容</p>", true, FileUtil.file("f:/ecaop-client-0.0.2-SNAPSHOT.jar"));
    }

    private String preComment = null;
    private void c(String msg) {
        System.out.printf("\t备注:%s%n",msg);
    }
    private void p1(String type1, Object value1, String type2, Object value2) {
        p(type1, value1, type2, value2, "format1");
    }
    private void p2(String type1, Object value1, String type2, Object value2) {
        p(type1, value1, type2, value2, "format2");
    }
    private void p3(String type1, Object value1) {
        p(type1, value1, "", "", "format3");
    }

    private void p(String type1, Object value1, String type2, Object value2, String format) {
        try {
            throw new Exception();
        } catch (Exception e) {

            String methodName = getTestMethodName(e.getStackTrace());
            Method m =ReflectUtil.getMethod(this.getClass(), methodName);
            Comment annotation = m.getAnnotation(Comment.class);
            if(null!=annotation) {
                String comment= annotation.value();
                if(!comment.equals(preComment)) {
                    System.out.printf("%n%s 例子: %n%n",comment);
                    preComment = comment;
                }

            }
        }
        int padLength = 12;
        type1=StrUtil.padEnd(type1,padLength,Convert.toSBC(" ").charAt(0));
        type2= StrUtil.padEnd(type2,padLength,Convert.toSBC(" ").charAt(0));
        if("format1".equals(format)) {
            System.out.printf("\t%s的:\t\"%s\" %n\t被转换为----->%n\t%s的 :\t\"%s\" %n%n",type1,value1, type2, value2);
        }
        if("format2".equals(format)) {
            System.out.printf("\t基于 %s:\t\"%s\" %n\t获取 %s:\t\"%s\"%n%n",type1,value1, type2, value2);
        }
        if("format3".equals(format)) {
            System.out.printf("\t%s:\t\"%s\" %n\t%n",type1,value1);

        }
    }

    private String getTestMethodName(StackTraceElement[] stackTrace) {
        for (StackTraceElement se : stackTrace) {
            String methodName = se.getMethodName();
            if(methodName.startsWith("test"))
                return methodName;
        }
        return null;
    }

    @Target({METHOD,TYPE})
    @Retention(RetentionPolicy.RUNTIME)
    @Inherited
    @Documented
    public @interface Comment {
        String value();
    }
}
"C:\Program Files\Java\jdk1.8.0_171\bin\java" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2017.3.2\lib\idea_rt.jar=57228:C:\Program Files\JetBrains\IntelliJ IDEA 2017.3.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\JetBrains\IntelliJ IDEA 2017.3.2\lib\idea_rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2017.3.2\plugins\junit\lib\junit-rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2017.3.2\plugins\junit\lib\junit5-rt.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\rt.jar;C:\kkk\st-web\target\test-classes;C:\kkk\st-web\target\classes;C:\kkk\st-web\src\lib\short_url-1.0-SNAPSHOT.jar;C:\kkk\st-web\src\lib\ecaop-client-0.0.2-SNAPSHOT.jar;C:\kkk\st-web\src\lib\ojdbc6-11.2.0.1.jar;C:\kkk\st-base\target\classes;F:\Tools\java\apache-maven-3.5.0\repository\org\bouncycastle\bcprov-jdk15on\1.55\bcprov-jdk15on-1.55.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\boot\spring-boot-starter-web\2.1.2.RELEASE\spring-boot-starter-web-2.1.2.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\boot\spring-boot-starter\2.1.2.RELEASE\spring-boot-starter-2.1.2.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\boot\spring-boot\2.1.2.RELEASE\spring-boot-2.1.2.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\boot\spring-boot-autoconfigure\2.1.2.RELEASE\spring-boot-autoconfigure-2.1.2.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\boot\spring-boot-starter-logging\2.1.2.RELEASE\spring-boot-starter-logging-2.1.2.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;F:\Tools\java\apache-maven-3.5.0\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\apache\logging\log4j\log4j-to-slf4j\2.11.1\log4j-to-slf4j-2.11.1.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\apache\logging\log4j\log4j-api\2.11.1\log4j-api-2.11.1.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\yaml\snakeyaml\1.23\snakeyaml-1.23.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\boot\spring-boot-starter-json\2.1.2.RELEASE\spring-boot-starter-json-2.1.2.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.8\jackson-datatype-jdk8-2.9.8.jar;F:\Tools\java\apache-maven-3.5.0\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.8\jackson-datatype-jsr310-2.9.8.jar;F:\Tools\java\apache-maven-3.5.0\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.8\jackson-module-parameter-names-2.9.8.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\hibernate\validator\hibernate-validator\6.0.14.Final\hibernate-validator-6.0.14.Final.jar;F:\Tools\java\apache-maven-3.5.0\repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;F:\Tools\java\apache-maven-3.5.0\repository\com\fasterxml\classmate\1.4.0\classmate-1.4.0.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\spring-web\5.1.4.RELEASE\spring-web-5.1.4.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\spring-beans\5.1.4.RELEASE\spring-beans-5.1.4.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\spring-webmvc\5.1.4.RELEASE\spring-webmvc-5.1.4.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\spring-context\5.1.4.RELEASE\spring-context-5.1.4.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\spring-expression\5.1.4.RELEASE\spring-expression-5.1.4.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\boot\spring-boot-starter-tomcat\2.1.2.RELEASE\spring-boot-starter-tomcat-2.1.2.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.14\tomcat-embed-core-9.0.14.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.14\tomcat-embed-el-9.0.14.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.14\tomcat-embed-websocket-9.0.14.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\boot\spring-boot-starter-test\2.1.2.RELEASE\spring-boot-starter-test-2.1.2.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\boot\spring-boot-test\2.1.2.RELEASE\spring-boot-test-2.1.2.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\boot\spring-boot-test-autoconfigure\2.1.2.RELEASE\spring-boot-test-autoconfigure-2.1.2.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\com\jayway\jsonpath\json-path\2.4.0\json-path-2.4.0.jar;F:\Tools\java\apache-maven-3.5.0\repository\net\minidev\json-smart\2.3\json-smart-2.3.jar;F:\Tools\java\apache-maven-3.5.0\repository\net\minidev\accessors-smart\1.2\accessors-smart-1.2.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\assertj\assertj-core\3.11.1\assertj-core-3.11.1.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\mockito\mockito-core\2.23.4\mockito-core-2.23.4.jar;F:\Tools\java\apache-maven-3.5.0\repository\net\bytebuddy\byte-buddy-agent\1.9.7\byte-buddy-agent-1.9.7.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\objenesis\objenesis\2.6\objenesis-2.6.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\hamcrest\hamcrest-library\1.3\hamcrest-library-1.3.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\skyscreamer\jsonassert\1.5.0\jsonassert-1.5.0.jar;F:\Tools\java\apache-maven-3.5.0\repository\com\vaadin\external\google\android-json\0.0.20131108.vaadin1\android-json-0.0.20131108.vaadin1.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\spring-core\5.1.4.RELEASE\spring-core-5.1.4.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\spring-jcl\5.1.4.RELEASE\spring-jcl-5.1.4.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\spring-test\5.1.4.RELEASE\spring-test-5.1.4.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\xmlunit\xmlunit-core\2.6.2\xmlunit-core-2.6.2.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\apache\axis\axis\1.4\axis-1.4.jar;F:\Tools\java\apache-maven-3.5.0\repository\javax\xml\rpc\javax.xml.rpc-api\1.1.1\javax.xml.rpc-api-1.1.1.jar;F:\Tools\java\apache-maven-3.5.0\repository\commons-codec\commons-codec\1.10\commons-codec-1.10.jar;F:\Tools\java\apache-maven-3.5.0\repository\dom4j\dom4j\1.6.1\dom4j-1.6.1.jar;F:\Tools\java\apache-maven-3.5.0\repository\xml-apis\xml-apis\1.4.01\xml-apis-1.4.01.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\apache\httpcomponents\httpcore\4.4.5\httpcore-4.4.5.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\apache\httpcomponents\httpclient\4.5.6\httpclient-4.5.6.jar;F:\Tools\java\apache-maven-3.5.0\repository\commons-httpclient\commons-httpclient\3.1\commons-httpclient-3.1.jar;F:\Tools\java\apache-maven-3.5.0\repository\commons-logging\commons-logging\1.0.4\commons-logging-1.0.4.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\projectlombok\lombok\1.18.4\lombok-1.18.4.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\redisson\redisson\3.6.5\redisson-3.6.5.jar;F:\Tools\java\apache-maven-3.5.0\repository\io\netty\netty-common\4.1.31.Final\netty-common-4.1.31.Final.jar;F:\Tools\java\apache-maven-3.5.0\repository\io\netty\netty-codec\4.1.31.Final\netty-codec-4.1.31.Final.jar;F:\Tools\java\apache-maven-3.5.0\repository\io\netty\netty-buffer\4.1.31.Final\netty-buffer-4.1.31.Final.jar;F:\Tools\java\apache-maven-3.5.0\repository\io\netty\netty-transport\4.1.31.Final\netty-transport-4.1.31.Final.jar;F:\Tools\java\apache-maven-3.5.0\repository\io\netty\netty-resolver\4.1.31.Final\netty-resolver-4.1.31.Final.jar;F:\Tools\java\apache-maven-3.5.0\repository\io\netty\netty-resolver-dns\4.1.31.Final\netty-resolver-dns-4.1.31.Final.jar;F:\Tools\java\apache-maven-3.5.0\repository\io\netty\netty-codec-dns\4.1.31.Final\netty-codec-dns-4.1.31.Final.jar;F:\Tools\java\apache-maven-3.5.0\repository\io\netty\netty-handler\4.1.31.Final\netty-handler-4.1.31.Final.jar;F:\Tools\java\apache-maven-3.5.0\repository\javax\cache\cache-api\1.1.0\cache-api-1.1.0.jar;F:\Tools\java\apache-maven-3.5.0\repository\io\projectreactor\reactor-core\3.2.5.RELEASE\reactor-core-3.2.5.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\reactivestreams\reactive-streams\1.0.2\reactive-streams-1.0.2.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;F:\Tools\java\apache-maven-3.5.0\repository\com\fasterxml\jackson\dataformat\jackson-dataformat-yaml\2.9.8\jackson-dataformat-yaml-2.9.8.jar;F:\Tools\java\apache-maven-3.5.0\repository\net\bytebuddy\byte-buddy\1.9.7\byte-buddy-1.9.7.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\jodd\jodd-bean\3.7.1\jodd-bean-3.7.1.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\jodd\jodd-core\3.7.1\jodd-core-3.7.1.jar;F:\Tools\java\apache-maven-3.5.0\repository\io\netty\netty-all\4.1.25.Final\netty-all-4.1.25.Final.jar;F:\Tools\java\apache-maven-3.5.0\repository\com\fasterxml\jackson\core\jackson-core\2.9.0\jackson-core-2.9.0.jar;F:\Tools\java\apache-maven-3.5.0\repository\com\fasterxml\jackson\core\jackson-databind\2.9.0\jackson-databind-2.9.0.jar;F:\Tools\java\apache-maven-3.5.0\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;F:\Tools\java\apache-maven-3.5.0\repository\axis\axis-wsdl4j\1.5.1\axis-wsdl4j-1.5.1.jar;F:\Tools\java\apache-maven-3.5.0\repository\cn\hutool\hutool-all\4.3.1\hutool-all-4.3.1.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\apache\poi\poi-ooxml\3.17\poi-ooxml-3.17.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\apache\poi\poi\3.17\poi-3.17.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\apache\commons\commons-collections4\4.1\commons-collections4-4.1.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\apache\poi\poi-ooxml-schemas\3.17\poi-ooxml-schemas-3.17.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\apache\xmlbeans\xmlbeans\2.6.0\xmlbeans-2.6.0.jar;F:\Tools\java\apache-maven-3.5.0\repository\stax\stax-api\1.0.1\stax-api-1.0.1.jar;F:\Tools\java\apache-maven-3.5.0\repository\com\github\virtuald\curvesapi\1.04\curvesapi-1.04.jar;F:\Tools\java\apache-maven-3.5.0\repository\xerces\xercesImpl\2.12.0\xercesImpl-2.12.0.jar;F:\Tools\java\apache-maven-3.5.0\repository\junit\junit\4.12\junit-4.12.jar;F:\Tools\java\apache-maven-3.5.0\repository\javax\mail\mail\1.4.7\mail-1.4.7.jar;F:\Tools\java\apache-maven-3.5.0\repository\javax\activation\activation\1.1\activation-1.1.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\boot\spring-boot-starter-data-redis\2.1.2.RELEASE\spring-boot-starter-data-redis-2.1.2.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\data\spring-data-redis\2.1.4.RELEASE\spring-data-redis-2.1.4.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\data\spring-data-keyvalue\2.1.4.RELEASE\spring-data-keyvalue-2.1.4.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\data\spring-data-commons\2.1.4.RELEASE\spring-data-commons-2.1.4.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\spring-tx\5.1.4.RELEASE\spring-tx-5.1.4.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\spring-context-support\5.1.4.RELEASE\spring-context-support-5.1.4.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\io\lettuce\lettuce-core\5.1.3.RELEASE\lettuce-core-5.1.3.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\boot\spring-boot-starter-thymeleaf\2.1.2.RELEASE\spring-boot-starter-thymeleaf-2.1.2.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\thymeleaf\thymeleaf-spring5\3.0.11.RELEASE\thymeleaf-spring5-3.0.11.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\thymeleaf\thymeleaf\3.0.11.RELEASE\thymeleaf-3.0.11.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\attoparser\attoparser\2.0.5.RELEASE\attoparser-2.0.5.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\unbescape\unbescape\1.1.6.RELEASE\unbescape-1.1.6.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\thymeleaf\extras\thymeleaf-extras-java8time\3.0.2.RELEASE\thymeleaf-extras-java8time-3.0.2.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\boot\spring-boot-starter-web-services\2.1.2.RELEASE\spring-boot-starter-web-services-2.1.2.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\com\sun\xml\messaging\saaj\saaj-impl\1.5.0\saaj-impl-1.5.0.jar;F:\Tools\java\apache-maven-3.5.0\repository\javax\xml\soap\javax.xml.soap-api\1.4.0\javax.xml.soap-api-1.4.0.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\jvnet\mimepull\mimepull\1.9.10\mimepull-1.9.10.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\jvnet\staxex\stax-ex\1.8\stax-ex-1.8.jar;F:\Tools\java\apache-maven-3.5.0\repository\javax\xml\ws\jaxws-api\2.3.1\jaxws-api-2.3.1.jar;F:\Tools\java\apache-maven-3.5.0\repository\javax\xml\bind\jaxb-api\2.3.1\jaxb-api-2.3.1.jar;F:\Tools\java\apache-maven-3.5.0\repository\javax\activation\javax.activation-api\1.2.0\javax.activation-api-1.2.0.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\spring-oxm\5.1.4.RELEASE\spring-oxm-5.1.4.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\ws\spring-ws-core\3.0.6.RELEASE\spring-ws-core-3.0.6.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\ws\spring-xml\3.0.6.RELEASE\spring-xml-3.0.6.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\commons-io\commons-io\2.5\commons-io-2.5.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\mybatis\spring\boot\mybatis-spring-boot-starter\1.3.2\mybatis-spring-boot-starter-1.3.2.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\mybatis\spring\boot\mybatis-spring-boot-autoconfigure\1.3.2\mybatis-spring-boot-autoconfigure-1.3.2.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\mybatis\mybatis\3.4.6\mybatis-3.4.6.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\mybatis\mybatis-spring\1.3.2\mybatis-spring-1.3.2.jar;F:\Tools\java\apache-maven-3.5.0\repository\mysql\mysql-connector-java\8.0.13\mysql-connector-java-8.0.13.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\boot\spring-boot-starter-aop\2.1.2.RELEASE\spring-boot-starter-aop-2.1.2.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\spring-aop\5.1.4.RELEASE\spring-aop-5.1.4.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\aspectj\aspectjweaver\1.9.2\aspectjweaver-1.9.2.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\boot\spring-boot-starter-jdbc\2.1.2.RELEASE\spring-boot-starter-jdbc-2.1.2.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\com\zaxxer\HikariCP\3.2.0\HikariCP-3.2.0.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\springframework\spring-jdbc\5.1.4.RELEASE\spring-jdbc-5.1.4.RELEASE.jar;F:\Tools\java\apache-maven-3.5.0\repository\com\alibaba\druid\1.1.10\druid-1.1.10.jar;F:\Tools\java\apache-maven-3.5.0\repository\com\alibaba\fastjson\1.2.51\fastjson-1.2.51.jar;F:\Tools\java\apache-maven-3.5.0\repository\commons-discovery\commons-discovery\0.5\commons-discovery-0.5.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\eclipse\birt\runtime\3_7_1\javax.wsdl\1.5.1\javax.wsdl-1.5.1.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\quartz-scheduler\quartz\2.3.0\quartz-2.3.0.jar;F:\Tools\java\apache-maven-3.5.0\repository\com\mchange\mchange-commons-java\0.2.11\mchange-commons-java-0.2.11.jar;F:\Tools\java\apache-maven-3.5.0\repository\javax\servlet\servlet-api\2.5\servlet-api-2.5.jar;F:\Tools\java\apache-maven-3.5.0\repository\org\mybatis\generator\mybatis-generator-core\1.3.5\mybatis-generator-core-1.3.5.jar" com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 com.unicom.st.stweb.happaystudyactivity.coursestudy.controller.TestMail,test1

cn.hutool.extra.mail.MailException: MessagingException: Could not connect to SMTP host: smtp.163.com, port: 25, response: 554

	at cn.hutool.extra.mail.Mail.send(Mail.java:229)
	at cn.hutool.extra.mail.MailUtil.send(MailUtil.java:158)
	at cn.hutool.extra.mail.MailUtil.send(MailUtil.java:144)
	at com.unicom.st.stweb.happaystudyactivity.coursestudy.controller.TestMail.test1(TestMail.java:42)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.163.com, port: 25, response: 554
	at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1949)
	at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
	at javax.mail.Service.connect(Service.java:317)
	at javax.mail.Service.connect(Service.java:176)
	at javax.mail.Service.connect(Service.java:125)
	at javax.mail.Transport.send0(Transport.java:194)
	at javax.mail.Transport.send(Transport.java:124)
	at cn.hutool.extra.mail.Mail.doSend(Mail.java:241)
	at cn.hutool.extra.mail.Mail.send(Mail.java:227)
	... 26 more


Process finished with exit code -1





回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到





2019-05-08 qq邮箱
yaoa



hutool 4.5.8 padEnd -> padAfter qq邮箱 account.setSslEnable(true);
 <!--hutool-->
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>4.5.8</version>
        </dependency>

///////////////////


@Before
    public void prepareMailAccount() {
        account = new MailAccount();
        account.setHost("smtp.qq.com");
        account.setPort(465);
        account.setAuth(true);
        account.setFrom("xxxxx@qq.com"); //假邮箱,请自己申请真实邮箱
        account.setUser("xxxxx@qq.com"); //假邮箱,请自己申请真实邮箱
        account.setPass("xxxxxxxxxxxxxx"); //假密码,请自己申请真实邮箱
        account.setSslEnable(true); //qq邮箱要加密
    }

//////////////////////

type1 = StrUtil.padAfter(type1,padLength, Convert.toSBC(" ").charAt(0));
type2 = StrUtil.padAfter(type2,padLength, Convert.toSBC(" ").charAt(0));

							





回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到





2019-03-09 运行不了啊。大佬




提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
关于 JAVA 应用-hutool-邮件工具 的提问

尽量提供截图代码异常信息,有助于分析和解决问题。 也可进本站QQ群交流: 1001964108
提问尽量提供完整的代码,环境描述,越是有利于问题的重现,您的问题越能更快得到解答。
对教程中代码有疑问,请提供是哪个步骤,哪一行有疑问,这样便于快速定位问题,提高问题得到解答的速度
在已经存在的几千个提问里,有相当大的比例,是因为使用了和站长不同版本的开发环境导致的,比如 jdk, eclpise, idea, mysql,tomcat 等等软件的版本不一致。
请使用和站长一样的版本,可以节约自己大量的学习时间。 站长把教学中用的软件版本整理了,都统一放在了这里, 方便大家下载: http://how2j.cn/k/helloworld/helloworld-version/1718.html

上传截图