You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用JavaMail API无法连接Protonmail的问题求助

Troubleshooting Java Mail Sender with Protonmail (Works with Gmail)

Hey there! Let's dig into why your Java mail program works flawlessly with Gmail but won't cooperate with Protonmail. From the debug log snippet you shared, it’s clear you’re using JavaMail 1.4.7—this is a major red flag, since this version is over a decade old and lacks support for modern security protocols Protonmail requires. Let’s walk through the fixes step by step:

1. Upgrade JavaMail to a Recent Version

JavaMail 1.4.7 doesn’t support TLS 1.2+, which is mandatory for Protonmail’s SMTP server. You’ll need to update to at least JavaMail 1.6.2 (the last release under the javax.mail package) or switch to Jakarta Mail (the modern successor, if your project can handle the package rename).

If you’re using Maven, add this dependency:

<dependency>
    <groupId>com.sun.mail</groupId>
    <artifactId>javax.mail</artifactId>
    <version>1.6.2</version>
</dependency>

For Gradle:

implementation 'com.sun.mail:javax.mail:1.6.2'

2. Use Protonmail’s Correct SMTP Configuration

Protonmail’s SMTP settings differ from Gmail’s—double-check your code uses these exact values:

  • SMTP Host: smtp.protonmail.com
  • Port:
    • 587 (recommended, uses STARTTLS)
    • 465 (SSL/TLS direct connection)
  • Authentication: Required (use your Protonmail username + password, or an App Password if you have 2FA enabled)
  • Encryption:
    • For port 587: Enable STARTTLS
    • For port 465: Enable SSL/TLS

3. Fix Authentication (Critical if 2FA is Enabled)

If you’ve turned on two-factor authentication (2FA) for your Protonmail account, your regular password won’t work for SMTP. You need to generate an App Password from your Protonmail account settings:

  1. Go to Protonmail → Settings → Security → App passwords
  2. Create a new app password for your Java mail program
  3. Use this app password instead of your main account password in your SmtpAuthenticator class

Ensure your SmtpAuthenticator correctly implements javax.mail.Authenticator:

public class SmtpAuthenticator extends Authenticator {
    private String username;
    private String password;

    public SmtpAuthenticator(String username, String password) {
        this.username = username;
        this.password = password;
    }

    @Override
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(username, password);
    }
}

4. Force Modern TLS & Enable Debugging

Add these properties to your session configuration to enforce TLS 1.2 and get more detailed debug logs:

Properties props = new Properties();
// Core Protonmail SMTP settings
props.put("mail.smtp.host", "smtp.protonmail.com");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
// Force STARTTLS and TLS 1.2
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.starttls.required", "true");
props.put("mail.smtp.ssl.protocols", "TLSv1.2");
// Trust Protonmail's SSL certificate
props.put("mail.smtp.ssl.trust", "smtp.protonmail.com");
// Enable full debug logging to diagnose issues
props.put("mail.smtp.debug", "true");

// Initialize session with authenticator
Session session = Session.getInstance(props, new SmtpAuthenticator("your-proton-username", "your-app-password"));

5. Check Network/Firewall Restrictions

Sometimes your local firewall or network provider blocks Protonmail’s SMTP ports. Test connectivity by running this command in your terminal:

telnet smtp.protonmail.com 587

If it fails to connect, whitelist the port or switch to port 465.

Final Note

The most likely root cause is the outdated JavaMail version. Even if you fix all other settings, JavaMail 1.4.7 can’t communicate with Protonmail’s server due to security protocol mismatches. Upgrading should resolve most issues.

内容的提问来源于stack exchange,提问作者Cl00e9ment

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:12:56