gpt4 book ai didi

带有 Gmail : 535-5. 7.1 用户名和密码的 JavaMail 不被接受

转载 作者:搜寻专家 更新时间:2023-10-30 19:49:26 25 4
gpt4 key购买 nike

当我尝试使用 JavaMail API 发送邮件时出现此错误。我确定用户名和密码 100% 正确。我连接的 Gmail 帐户是一个旧帐户,因为他们说它需要时间才能与新帐户一起使用。

DEBUG SMTP RCVD: 535-5.7.1 Username and Password not accepted. Learn more at535 5.7.1 http://mail.google.com/support/bin/answer.py?answer=14257 x35sm3011668wfh.6javax.mail.SendFailedException: Sending failed;  nested exception is:        javax.mail.AuthenticationFailedException        at javax.mail.Transport.send0(Transport.java:218)        at javax.mail.Transport.send(Transport.java:80)        at Main.(Main.java:41)        at Main.main(Main.java:51)

这是我的代码:

import javax.mail.*;import javax.mail.internet.*;import java.util.*;public class Main{    String  d_email = "abc@gmail.com",            d_password = "pass",            d_host = "smtp.gmail.com",            d_port  = "465",            m_to = "abc@gmail.com",            m_subject = "Testing",            m_text = "testing email.";    public Main()    {        Properties props = new Properties();        props.put("mail.smtp.user", d_email);        props.put("mail.smtp.host", d_host);        props.put("mail.smtp.port", d_port);        props.put("mail.smtp.starttls.enable","true");        props.put("mail.smtp.auth", "true");        props.put("mail.smtp.debug", "true");        props.put("mail.smtp.socketFactory.port", d_port);        props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");        props.put("mail.smtp.socketFactory.fallback", "false");        SecurityManager security = System.getSecurityManager();        try        {            Authenticator auth = new SMTPAuthenticator();            Session session = Session.getInstance(props, auth);            session.setDebug(true);            MimeMessage msg = new MimeMessage(session);            msg.setText(m_text);            msg.setSubject(m_subject);            msg.setFrom(new InternetAddress(d_email));            msg.addRecipient(Message.RecipientType.TO, new InternetAddress(m_to));            Transport.send(msg);        }        catch (Exception mex)        {            mex.printStackTrace();        }     }    public static void main(String[] args)    {        Main blah = new Main();    }    private class SMTPAuthenticator extends javax.mail.Authenticator    {        public PasswordAuthentication getPasswordAuthentication()        {            return new PasswordAuthentication(d_email, d_password);        }    }}

最佳答案

我有同样的问题:我指的是这个 link ,我已按照以下对我有用的步骤进行操作。

默认情况下,Gmail 帐户是高度安全的。当我们从非 gmail 工具使用 gmail smtp 时,电子邮件被阻止。要在我们的本地环境中进行测试,请降低您的 gmail 帐户的安全性

  1. 登录 Gmail。
  2. 访问 URL 为 https://www.google.com/settings/security/lesssecureapps
  3. 选择“开启”

关于带有 Gmail : 535-5. 7.1 用户名和密码的 JavaMail 不被接受,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2965251/

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