无法使用 zoho smtp 服务器发送邮件

Unable to send mail using zoho smtp server

我正在尝试使用 Zoho SMTP 服务器发送邮件,代码如下:

 public void sendEmail(Email email) {
        Properties props = setupMailEnv();

        Session session = Session.getDefaultInstance(props,
                new javax.mail.Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication("sssxxxx@xxx.com", "xxxxx");
                    }
                });

        try {

            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress(email.getFromMailId()));
            message.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse(email.getToEmailId()));
            message.setSubject(email.getSubject());
            message.setText(email.getBody());

            Transport.send(message);

            log.info("Mail Sent.");

        } catch (MessagingException e) {
            throw e;
        }

    }

    private Properties setupMailEnv() {
        Properties props = new Properties();
        props.put("mail.smtp.host", "smtp.zoho.com");
        props.put("mail.smtp.socketFactory.port", "465");
        props.put("mail.smtp.socketFactory.class", javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.port", "465");
        props.setProperty("mail.smtp.socketFactory.fallback", "false");
        props.put("mail.smtp.startssl.enable", "true");
        props.put("mail.smtp.starttls.enable", "false");
        return props;
    }

当我执行这个程序时,它给出了以下异常:

javax.mail.MessagingException: Can't send command to SMTP host;
  nested exception is:
    java.net.SocketException: Connection closed by remote host

我参考了 Zoho 论坛,但其中 none 提供了解决方案。我该如何解决这个问题?

我代表 Zoho Mail 与您联系。

请将starttls.enable设置为True并检查您是否能够发送邮件。也尝试使用端口号“587”并检查它是否有效。

如果问题仍然存在,请将包含完整错误日志的电子邮件发送至支持[at]zohomail[dot]com。还要提及您尝试从中发送邮件的 Zoho 电子邮件地址。此信息将帮助我们进一步帮助您。

此致, 卡尔提克.

我使用了下面的属性来调试错误:

props.put("mail.debug", "true");

问题出在发件人地址上。发件人地址应与 :

中的地址匹配
new PasswordAuthentication("sssxxxx@xxx.com", "xxxxx");

我更改了它,一切都按预期正常工作。