You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

使用JavaMail开发Yandex邮件收发应用遇认证失败问题求助

Fixing Yandex SMTP 535 Authentication Failed Error in JavaMail

Hey there, that 535 "Invalid user or password" error when sending emails via Yandex SMTP is a pretty common pitfall—let’s walk through the most likely fixes to get your app working:

First, Double-Check Your Credentials

  • Username must be your full Yandex email address: Don’t just use yourname—it needs to be yourname@yandex.com (or your custom domain if you’ve set one up).
  • Password considerations:
    • If you have two-factor authentication (2FA) enabled on your Yandex account, your regular login password won’t work here. You need to generate a special app password for your JavaMail application. Head to your Yandex account’s Security settings, find "App passwords", create a new one for mail, and use that password instead.
    • Make sure you’re not accidentally using a wrong password (typos happen—double-check case sensitivity too!).

Verify SMTP Server Configuration

Yandex’s SMTP setup has specific requirements—ensure your Properties are configured correctly:

  • Correct host: smtp.yandex.com
  • Valid ports: Use 465 with SSL or 587 with TLS (don’t mix these up)
  • Enable authentication and encryption flags

Here’s a corrected configuration snippet to replace your current props setup:

Properties props = System.getProperties();
// For SSL (port 465)
props.put("mail.smtp.host", "smtp.yandex.com");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.ssl.enable", "true");

// OR for TLS (port 587)
// props.put("mail.smtp.host", "smtp.yandex.com");
// props.put("mail.smtp.port", "587");
// props.put("mail.smtp.auth", "true");
// props.put("mail.smtp.starttls.enable", "true");

Ensure Your Account Allows SMTP Access

Log into your Yandex Mail account, go to Settings > Mail clients, and make sure the "Allow access to mail from external applications" option is turned on. Yandex disables this by default for some accounts, so this is a critical step.

Fix the Session Authentication

Make sure you’re properly passing the credentials to the Session object using an Authenticator:

Session session = Session.getInstance(props, new javax.mail.Authenticator() {
    @Override
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(from, pass);
    }
});

Test Again

After making these changes, try sending the email again. If you still run into issues, check if your network is blocking SMTP traffic (some firewalls or ISPs restrict port 465/587), but the above steps should resolve 90% of authentication failures with Yandex.

内容的提问来源于stack exchange,提问作者Mr. Kevin

火山引擎 最新活动