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 =

相关内容

热门资讯

实操分享!微乐苏州麻将透视软件... 实操分享!微乐苏州麻将透视软件(开挂),微乐苏州麻将竟然是真的有开挂方案1、微乐苏州麻将破解器简单,...
推荐一款!奕乐贵州麻将能不能开... 推荐一款!奕乐贵州麻将能不能开挂(作弊器),奕乐贵州麻将原来真的有作弊器经验奕乐贵州麻将透视方法中分...
实测分享!粤乐广东麻确实真的有... 实测分享!粤乐广东麻确实真的有挂(外挂),粤乐广东麻切实真的有外挂插件1、许多玩家不知道粤乐广东麻辅...
解密关于!多乐跑得快开挂工具(... 解密关于!多乐跑得快开挂工具(辅助器),多乐跑得快一直有辅助器学习1、金币登录送、破产送、升级送、活...
盘点十款!雀神麻将到底有没有透... 盘点十款!雀神麻将到底有没有透视挂(外挂),雀神麻将确实存在有外挂妙招一、雀神麻将游戏安装教程牌型概...
玩家必看秘籍!乐吧游戏有挂吗(... 玩家必看秘籍!乐吧游戏有挂吗(辅助器),乐吧游戏本来是真的有辅助器秘籍小薇(辅助器软件下载)致您一封...
玩家必知教程!熊猫二人麻将透视... 玩家必知教程!熊猫二人麻将透视方法(外挂),熊猫二人麻将切实真的有外挂策略1、在熊猫二人麻将插件功能...
重大发现!朋朋棋牌开挂破解(透... 重大发现!朋朋棋牌开挂破解(透视挂),朋朋棋牌都是是真的有透视挂技巧在进入朋朋棋牌软件靠谱后,参与本...
技术分享!微乐江苏麻将透视挂(... 技术分享!微乐江苏麻将透视挂(透视),微乐江苏麻将一贯是有透视要领1、打开软件启动之后找到中间准星的...
重大通报!花城棋舍真的有挂(辅... 重大通报!花城棋舍真的有挂(辅助挂),花城棋舍总是有辅助挂窍门暗藏猫腻,小编详细说明花城棋舍破解器有...