首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从java servlet发送邮件的身份验证失败。

从java servlet发送邮件的身份验证失败。
EN

Server Fault用户
提问于 2020-07-14 21:17:12
回答 1查看 2.3K关注 0票数 0

Centos7,tomcat 9,Exim 4.94

将我所有的tomcat应用程序从centos6转移到centos7服务器。Tomcat版本为9,在两台服务器上都是相同的。

我从其中一个java应用程序发送电子邮件。

代码语言:javascript
运行
复制
public void sendEmail(String toAddress,
        String subject, String message) throws AddressException,
        MessagingException {

    // sets SMTP server properties
    Properties properties = new Properties();
    properties.put("mail.smtp.host", host);
    properties.put("mail.smtp.port", port);
    properties.put("mail.smtp.auth", "true");
    properties.put("mail.smtp.starttls.enable", "false");

    // creates a new session with an authenticator
    Authenticator auth = new Authenticator() {
        @Override
        public PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(user, pass);
        }
    };

    Session session = Session.getInstance(properties, auth);

    // creates a new e-mail message
    Message msg = new MimeMessage(session);

    msg.setFrom(new InternetAddress(user));
    InternetAddress[] toAddresses = { new InternetAddress(toAddress) };
    msg.setReplyTo(new javax.mail.Address[] {new javax.mail.internet.InternetAddress(replyTo)});
    msg.setRecipients(Message.RecipientType.TO, toAddresses);
    msg.setSubject(subject);
    msg.setSentDate(new Date());
    msg.setText(message);

    // sends the e-mail
    Transport.send(msg); 
}

变量主机= my,端口= 25

从命令行发送可以正常工作。

邮件-s“测试主题”scott@myaddress.com < /dev/null

通过servlet发送,我在catalina.out中得到了这个错误

代码语言:javascript
运行
复制
javax.mail.AuthenticationFailedException: 535 Incorrect authentication data
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:826)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:761)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:685)
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 util.EmailUtility.sendEmail(EmailUtility.java:86)

最后一行util.EmailUtility.sendEmail(EmailUtility.java:86)是对上述函数的调用。

我使用sendmail,因为它是在这个服务器上安装的。

编辑1。

我在上面的java应用函数sendEmail中设置了sendEmail(真),现在我在catalina.out中看到了这一点

代码语言:javascript
运行
复制
DEBUG: setDebug: JavaMail version 1.4.7
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "68.169.63.242", port 25, isSSL false
220 www.mbepapers.org ESMTP Exim 4.94 Wed, 15 Jul 2020 14:27:07 -0400
DEBUG SMTP: connected to host "68.169.63.242", port: 25

EHLO www.mbepapers.org
250-www.mbepapers.org Hello mbepapers.org [68.169.63.242]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-X_PIPE_CONNECT
250-AUTH PLAIN LOGIN CRAM-MD5
250-CHUNKING
250-STARTTLS
250 HELP
DEBUG SMTP: Found extension "SIZE", arg "52428800"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "X_PIPE_CONNECT", arg ""
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN CRAM-MD5"
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "HELP", arg ""
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN    DIGEST-MD5 NTLM 
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN failed
javax.mail.AuthenticationFailedException: 535 Incorrect authentication data

谢谢

EN

回答 1

Server Fault用户

发布于 2020-07-18 16:50:20

这绝对令人尴尬。在设置新服务器时,没有设置邮件服务器域名,这是造成此错误的原因之一。

535不正确的身份验证数据

在通过控制面板添加邮件域后,它开始按预期工作.

票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/1025234

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档