微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

“需要 530 身份验证”SMTP,我不知道为什么

如何解决“需要 530 身份验证”SMTP,我不知道为什么

我用 javax.mail 库编写了一个 emailSender。我不知道我的错误在哪里,因为在代码工作的视频中。

视频:https://www.youtube.com/watch?v=bkpHQD9e5hc&t=1630s

我也在这个网站上看到了另一个关于这个主题的问题,但这些问题的解决方案都没有解决我的问题

代码

public class MailSender {

    protected Session mailSession;

    public void login(String smtpHost,String smtpPort,String username,String password) {
        Properties props = new Properties();
        props.put("mail.smtp.host",smtpHost);
        props.put("mail.smtp.socketFactory.port",smtpPort);
        props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.auth","true");
        props.put("mail.smtp.port",smtpPort);

        Authenticator auth = new Authenticator() {
            @Override
            protected PasswordAuthentication getpasswordAuthentication() {
                return new PasswordAuthentication(username,password);
            }
        };

        this.mailSession = Session.getDefaultInstance(props,auth);
        System.out.println("Eingeloggt.");
    }

    public void send(String senderMail,String senderName,String receiverAddresses,String subject,String message,String password)
            throws MessagingException,IllegalStateException,UnsupportedEncodingException {
        if (mailSession == null) {
            throw new IllegalStateException("Du musst dich zuerst einloggen (login()-Methode)");
        }

        MimeMessage msg = new MimeMessage(mailSession);
        msg.addHeader("Content-type","text/HTML; charset=UTF-8");
        msg.addHeader("format","flowed");
        msg.addHeader("Content-transfer-encoding","8bit");

        msg.setFrom(new InternetAddress(senderMail,senderName));
        msg.setReplyTo(InternetAddress.parse(senderMail,false));
        msg.setSubject(subject,"UTF-8");
        msg.setText(message,"UTF-8");
        msg.setSentDate(new Date());

        msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(receiverAddresses,false));

        System.out.println("Versende E-Mail...");
        Transport.send(msg,username,password);
        System.out.println("E-Mail versendet.");
    }
}

解决方法

此错误消息来自安装在本地系统上的另一个电子邮件服务器:

如果它的“530 SMTP 身份验证是必需的”,则 POPcon 会尝试通过 IP 端口 25 (SMTP) 访问您的 Exchange 服务器,但该其他邮件服务器却以此特定错误消息进行响应。您需要从系统中删除 hMailServer 并重新启动 Exchange 或将两台服务器之一移动到不同的本地 IP 端口,因为两者不能在端口 25 上共存。您可以在 EXCHANGE 配置中选择 POPcon 尝试访问的 IP 端口POPcon 配置中的页面。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。