NutzCN Logo
问答 发邮件报错,密码邮箱都正确
发布于 2635天前 作者 老司机 3682 次浏览 复制 上一个帖子 下一个帖子
标签:

错误日志:

Exception in thread "main" org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.163.com:25
	at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1469)
	at com.shawn.App.main(App.java:20)
Caused by: javax.mail.AuthenticationFailedException: 550 User has no permission

	at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:932)
	at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:843)
	at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:748)
	at javax.mail.Service.connect(Service.java:388)
	at javax.mail.Service.connect(Service.java:246)
	at javax.mail.Service.connect(Service.java:195)
	at javax.mail.Transport.send0(Transport.java:254)
	at javax.mail.Transport.send(Transport.java:124)
	at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1459)
	... 1 more

邮箱配置:

mail.HostName=smtp.163.com
mail.SmtpPort=25
mail.UserName=xx2079947408
mail.Password=
mail.SSLOnConnect=false
mail.From=xx2079947408@163.com
mail.charset=UTF-8

密码没错,能登录

18 回复

主程序:

 Ioc ioc = new NutIoc(new ComboIocLoader("*js", "ioc/"));
        HtmlEmail email = ioc.get(HtmlEmail.class);
        email.setSubject("测试NutzBook");
        email.setMsg("This is a test mail ... :-)" + System.currentTimeMillis());
        email.addTo("2079947408@qq.com");//请务必改成您自己的邮箱啊!!!
        email.buildMimeMessage();
        email.sendMimeMessage();

没开通smtp权限吧

@wendal 那哪个邮箱是给普通用户开通smtp权限的呢?阿里云?或者网易怎么开通SMTP?

@wendal 开通好了以后又报错

Exception in thread "main" org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.163.com:25
	at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1469)
	at com.shawn.App.main(App.java:20)
Caused by: javax.mail.MessagingException: Exception reading response;
  nested exception is:
	java.net.SocketTimeoutException: Read timed out
	at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2369)
	at com.sun.mail.smtp.SMTPTransport.close(SMTPTransport.java:1353)
	at javax.mail.Transport.send0(Transport.java:257)
	at javax.mail.Transport.send(Transport.java:124)
	at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1459)
	... 1 more
Caused by: java.net.SocketTimeoutException: Read timed out
	at java.net.SocketInputStream.socketRead0(Native Method)
	at java.net.SocketInputStream.read(SocketInputStream.java:150)
	at java.net.SocketInputStream.read(SocketInputStream.java:121)
	at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:124)
	at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
	at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
	at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:92)
	at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2349)
	... 5 more

要么放弃,要么换aliyun的邮箱

@wendal 阿里云个人邮箱怎么开通smtp服务,百度了半天没有啊

@wendal 还是不行啊,把源码贴上
mail.properties

mail.HostName=smtp.mxhichina.com
mail.SmtpPort=25
mail.UserName=shawnxiaoxiao@aliyun.com
mail.Password=
mail.SSLOnConnect=false
mail.From=shawnxiaoxiao@aliyun.com
mail.charset=UTF-8

mail.js

var ioc = {
    conf: {
        type: "org.nutz.ioc.impl.PropertiesProxy",
        fields: {
            paths: ["custom/"]
        }
    },
    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')"}
        }
    }
};

App.java

public class App {

    public static void main(String[] args) throws Exception {
        Ioc ioc = new NutIoc(new ComboIocLoader("*js", "ioc/"));
        HtmlEmail email = ioc.get(HtmlEmail.class);
        email.setSubject("测试NutzBook");
        email.setMsg("This is a test mail ... :-)" + System.currentTimeMillis());
        email.addTo("2079947408@qq.com");//请务必改成您自己的邮箱啊!!!
        email.buildMimeMessage();
        email.sendMimeMessage();
    }
}

报错

Exception in thread "main" org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.mxhichina.com:25
	at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1469)
	at com.shawn.App.main(App.java:28)
Caused by: javax.mail.AuthenticationFailedException: 526 Authentication failure[0]

	at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:932)
	at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:843)
	at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:748)
	at javax.mail.Service.connect(Service.java:388)
	at javax.mail.Service.connect(Service.java:246)
	at javax.mail.Service.connect(Service.java:195)
	at javax.mail.Transport.send0(Transport.java:254)
	at javax.mail.Transport.send(Transport.java:124)
	at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1459)
	... 1 more

密码没错是我网页登陆阿里云邮箱的密码,已经无语了

smtp.aliyun.com 吧

@wendal 改成smtp.aliyun.com以后还是报错:

Exception in thread "main" 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:1469)
	at com.shawn.App.main(App.java:21)
Caused by: javax.mail.MessagingException: Exception reading response;
  nested exception is:
	java.net.SocketTimeoutException: Read timed out
	at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2369)
	at com.sun.mail.smtp.SMTPTransport.close(SMTPTransport.java:1353)
	at javax.mail.Transport.send0(Transport.java:257)
	at javax.mail.Transport.send(Transport.java:124)
	at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1459)
	... 1 more
Caused by: java.net.SocketTimeoutException: Read timed out
	at java.net.SocketInputStream.socketRead0(Native Method)
	at java.net.SocketInputStream.read(SocketInputStream.java:150)
	at java.net.SocketInputStream.read(SocketInputStream.java:121)
	at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:124)
	at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
	at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
	at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:92)
	at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2349)
	... 5 more

jdk,java mail,apache common mail的版本分别是多少

@wendal jdk1.8

  <!-- https://mvnrepository.com/artifact/javax.mail/javax.mail-api -->
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>javax.mail-api</artifactId>
            <version>1.6.0</version>
        </dependency>
  <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-email -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-email</artifactId>
            <version>1.5</version>
        </dependency>

具体的jdk版本

@wendal java version "1.8.0_91"
jdk 应该是最新的8u144

找个第三方封装库试试吧

试试看把密码改成授权码,上面我记得是填授权码,邮箱里能拿到授权码的.

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