我编写了一个微型Java程序来发送邮件。当我尝试从gmail发送邮件而不是从protonmail发送邮件时,它可以工作。这是代码:
Main class
MailSender class
SmtpAuthenticator class
这是日志:
DEBUG: JavaMail version 1.4.7
DEBUG: URL jar:file:/D:/Programmation/Java/Libraries/javamail-1.4.7/lib/gimap.jar!/META-INF/javamail.providers
DEBUG: successfully loaded resource: jar:file:/D:/Programmation/Java/Libraries/javamail-1.4.7/lib/gimap.jar!/META-INF/javamail.providers
DEBUG: URL jar:file:/D:/Programmation/Java/Libraries/javamail-1.4.7/lib/imap.jar!/META-INF/javamail.providers
DEBUG: successfully loaded resource: jar:file:/D:/Programmation/Java/Libraries/javamail-1.4.7/lib/imap.jar!/META-INF/javamail.providers
DEBUG: URL jar:file:/D:/Programmation/Java/Libraries/javamail-1.4.7/lib/pop3.jar!/META-INF/javamail.providers
DEBUG: successfully loaded resource: jar:file:/D:/Programmation/Java/Libraries/javamail-1.4.7/lib/pop3.jar!/META-INF/javamail.providers
DEBUG: URL jar:file:/D:/Programmation/Java/Libraries/javamail-1.4.7/lib/smtp.jar!/META-INF/javamail.providers
DEBUG: successfully loaded resource: jar:file:/D:/Programmation/Java/Libraries/javamail-1.4.7/lib/smtp.jar!/META-INF/javamail.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.gimap.GmailSSLStore=javax.mail.Provider[STORE,gimaps,com.sun.mail.gimap.GmailSSLStore,Oracle], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.gimap.GmailStore=javax.mail.Provider[STORE,gimap,com.sun.mail.gimap.GmailStore,Oracle], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], gimap=javax.mail.Provider[STORE,gimap,com.sun.mail.gimap.GmailStore,Oracle], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], gimaps=javax.mail.Provider[STORE,gimaps,com.sun.mail.gimap.GmailSSLStore,Oracle]}
DEBUG: URL jar:file:/D:/Programmation/Java/Libraries/javamail-1.4.7/lib/smtp.jar!/META-INF/javamail.address.map
DEBUG: successfully loaded resource: jar:file:/D:/Programmation/Java/Libraries/javamail-1.4.7/lib/smtp.jar!/META-INF/javamail.address.map
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "mail.protonmail.ch", port 587, isSSL false
421 Cannot connect to SMTP server ::ffff:185.70.40.101 (::ffff:185.70.40.101:587), connect error 10060
javax.mail.MessagingException: Could not connect to SMTP host: mail.protonmail.ch, port: 587, response: 421
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1949)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
at javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at MailSender.send(MailSender.java:50)
at Start.main(Start.java:6)
DEBUG SMTP: could not connect to host "mail.protonmail.ch", port: 587, response: 421
最佳答案
您无法连接到mail.protonmail.ch:587
,因为该服务不存在。没有文档说明此特定的SMTP服务器存在。您得到的connect error 10060
(连接超时)进一步证明了这一点。
如果要使用Protonmail,则需要使用ProtonMail Bridge。然后,它将在localhost上生成一个服务器套接字,然后可以连接到该套接字。参见:Setup Guide
您可以从此处下载网桥:https://protonmail.com/bridge/