AndroidStudio中如何解决javax.mail.AuthenticationFailedException?
创始人
2024-08-21 02:30:16
0
  1. 确认邮箱账号和密码是否正确。

  2. 确认邮箱服务商是否开启了IMAP/POP3服务。

  3. 检查代码中是否正确配置了SMTP/IMAP/POP3的相关参数。

参考代码:

使用JavaMail发送邮件:

String host = "smtp.gmail.com";
String port = "587";
String username = "your-email-address@gmail.com";
String password = "your-email-password";

Properties properties = new Properties();
properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.smtp.host", host);
properties.put("mail.smtp.port", port);
properties.put("mail.smtp.auth", "true");

Session session = Session.getInstance(properties,
        new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
            }
        });

try {
    Message message = new MimeMessage(session);
    message.setFrom(new InternetAddress("your-email-address@gmail.com"));
    message.setRecipients(
            Message.RecipientType.TO,
            InternetAddress.parse("recipient-email-address@example.com")
    );
    message.setSubject("Testing JavaMail API");
    message.setText("Dear Recipient," +
            "\n\nThis is a test email sent using JavaMail API. " +
            "Please do not reply to this email." +
            "\n\nThank you." +
            "\n\nBest regards," +
            "\nYour Name");

    Transport.send(message);

    System.out.println("Email sent successfully.");

} catch (MessagingException e) {
    e.printStackTrace();
}

使用JavaMail接收邮件:

String host = "imap.gmail.com";
String port = "993";
String username = "your-email-address@gmail.com";
String password = "your-email-password";

Properties properties = new Properties();
properties.put("mail.imap.host", host);
properties.put("mail.imap.port", port);
properties.put("mail.imap.starttls.enable", "true");
properties.put("mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory");

Session session = Session.getInstance(properties,
        new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
            }
        });

try {
    Store store =

相关内容

热门资讯

终于清楚!鸿狐大厅脚本,pok... 终于清楚!鸿狐大厅脚本,pokerrrr2辅助,线上教程(有挂总结);相信小伙伴都知道这个鸿狐大厅脚...
免费测试版!灯笼众娱脚本,微扑... 免费测试版!灯笼众娱脚本,微扑克辅助下载,曝光教程(详细教程);人气非常高,ai更新快且高清可以动的...
盘点几款!天天微友第三方辅助软... 盘点几款!天天微友第三方辅助软件下载,hhpoker辅助靠谱吗,规律教程(有挂透视)是一款可以让一直...
玩家必看分享!微信小程序跑得快... 玩家必看分享!微信小程序跑得快辅助脚本,aa poker辅助,技巧教程(有挂教程);是一款可以让一直...
一分钟揭秘!潮汕鱼虾蟹app源... 一分钟揭秘!潮汕鱼虾蟹app源码,购买的wpk辅助在哪里下载,黑科技教程(详细教程);一分钟揭秘!潮...
今日头条!胡易辅助软件,wep... 【福星临门,好运相随】;今日头条!胡易辅助软件,wepoker一直输的号能继续打吗,可靠技巧(真实有...
必备科技!微乐小程序微乐房间怎... 必备科技!微乐小程序微乐房间怎么开挂,wepoker透视脚本安卓,必赢教程(有挂教程);人气非常高,...
揭秘真相!情怀大陆dnf辅助,... 揭秘真相!情怀大陆dnf辅助,佛手在线大菠萝辅助,AI教程(有挂细节);相信小伙伴都知道这个佛手在线...
玩家必看教程!赣牌圈小程序破解... 玩家必看教程!赣牌圈小程序破解版,hhpoker德州透视,黑科技教程(有挂细节);赣牌圈小程序破解版...
最新研发!微信小程序辅助app... 您好:微信小程序辅助app下载这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多...