gpt4 book ai didi

Java SSL 电子邮件错误

转载 作者:搜寻专家 更新时间:2023-11-01 03:49:55 25 4
gpt4 key购买 nike

我正在经历这个 Link并尝试执行代码。

总结如下:

    private static final String SSL_FACTORY = "SendMailDemoSSLSocketFactory"; //SendMailDemoSSLSocketFactory extends SSLSocketFactory       

Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.submitter", emailUsername);
props.put("mail.smtp.user", emailUsername);
props.put("mail.smtp.host", smtpHostName);
props.put("mail.debug", debug);
props.put("mail.smtp.port", smtpPort);
props.put("mail.smtp.ssl.socketFactory.port", smtpPort);
props.put("mail.smtp.ssl.socketFactory.class", SSL_FACTORY);
props.put("mail.smtp.socketFactory.fallback", "true");
props.put("mail.smtp.ssl.enable", "true");
props.put("mail.smtp.starttls.enable", "true");
props.setProperty("mail.smtps.ssl.enable", "true");
props.put("mail.transport.protocol", "smtps");
props.put("mail.smtp.ssl.trust", smtpHostName);

Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(emailUsername,
emailPassword);
}
});

session.setDebug(Boolean.parseBoolean(debug));

Message msg = new MimeMessage(session);
//set message
SMTPSSLTransport transport = (SMTPSSLTransport) session
.getTransport("smtps");
transport.connect(smtpHostName, new Integer(smtpPort).intValue(),
emailUsername, emailPassword);
msg.saveChanges();

transport.sendMessage(msg, msg.getAllRecipients());

同样,我能够建立成功的连接,但身份验证不成功。我找不到代码哪里出错了。

DEBUG: JavaMail version 1.4ea
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.7.0_25\jre\lib\javamail.providers (The system cannot find the file specified)
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.providers
DEBUG: successfully loaded resource: /META-INF/javamail.default.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,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.address.map
DEBUG: successfully loaded file: C:\Program Files\Java\jdk1.7.0_25\jre\lib\javamail.address.map
DEBUG: setDebug: JavaMail version 1.4ea
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL true
220 smtp.gmail.com ESMTP xv9sm19052844pbc.2 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 465

EHLO test
250-smtp.gmail.com at your service, [182.64.100.170]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN XOAUTH"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
DEBUG SMTP: use8bit false

邮件来自: 530-5.5.1 需要身份验证。了解更多信息 530 5.5.1 https://support.google.com/mail/answer/14257 xv9sm19052844pbc.2-gsmtpcom.sun.mail.smtp.SMTPSendFailedException:530-5.5.1 需要身份验证。在 530 5.5.1 https://support.google.com/mail/answer/14257 了解更多信息xv9sm19052844pbc.2 - gsmtp

at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:959)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:583)
at edu.bhavesh.mail.smtp.ssl.SendMailDemo.sendSSLMessage(SendMailDemo.java:135)
at edu.bhavesh.mail.smtp.ssl.SendMailDemo.main(SendMailDemo.java:41)

com.sun.mail.smtp.SMTPSendFailedException:530-5.5.1 需要验证。了解更多信息 530 5.5.1 https://support.google.com/mail/answer/14257 xv9sm19052844pbc.2-gsmtp 退出

at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:959)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:583)
at edu.bhavesh.mail.smtp.ssl.SendMailDemo.sendSSLMessage(SendMailDemo.java:135)
at edu.bhavesh.mail.smtp.ssl.SendMailDemo.main(SendMailDemo.java:41)

221 2.0.0 closing connection xv9sm19052844pbc.2 - gsmtp

最佳答案

这只是 gmail smtp 所需的属性,我正在使用它:在我的类路径中使用 jars:

  • 邮件.jar
  • 激活.jar
  • additionnal.jar
  • commons-io-2.4.jar

    String sendingHost = "smtp.gmail.com";
    int sendingPort = 465;
    Properties props = new Properties();
    props.put("mail.smtp.host", sendingHost);
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.port", sendingPort + "");
    /**ADD THIS**/
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.starttls.required", "true");

    props.put("mail.smtp.SSL", "true");
    props.put("mail.smtp.ehlo", "true");
    /** **/

    Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication(email.getFromAccount().getEmail(), email.getFromAccount().getPassword());
    }
    });

关于Java SSL 电子邮件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31389426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com