【问题标题】:"530 Authentication required" SMTP and I don't know why“需要 530 身份验证” SMTP,我不知道为什么
【发布时间】:2021-05-17 06:23:12
【问题描述】:

我用 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 username, 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.");
    }
}

【问题讨论】:

    标签: java email smtp smtpclient


    【解决方案1】:

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

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

    【讨论】:

    • 但不是“需要 530 SMTP 身份验证”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-13
    • 2018-10-07
    • 1970-01-01
    • 1970-01-01
    • 2018-12-28
    • 1970-01-01
    • 2016-01-09
    相关资源
    最近更新 更多