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 =

相关内容

热门资讯

规律辅助挂!hhpoker有作... 规律辅助挂!hhpoker有作弊的吗,如何下载德普之星辅助软件,真是是有挂(果真有挂)1、用户打开应...
迎来新发展!约局吧德州真的存在... 迎来新发展!约局吧德州真的存在透视吗,智星菠萝透视,好像确实有挂(有挂讲解)1、很好的工具软件,可以...
据监测!werplan怎么作弊... 据监测!werplan怎么作弊,德普之星透视辅助软件下载,总是是真的有挂(了解有挂)1、德普之星透视...
经调查!aapoker辅助器怎... 经调查!aapoker辅助器怎么用,德普之星有透视辅助吗,果然存在有挂(有挂教程)在进入德普之星有透...
教程辅助挂!wepoker透视... 教程辅助挂!wepoker透视脚本免费下载,智星菠萝辅助,切实真的有挂(有挂分析)1.智星菠萝辅助 ...
2026版复盘!菠萝德普辅助器... 2026版复盘!菠萝德普辅助器免费版在哪里,德普之星app安卓版破解版,果然真的是有挂(确实有挂)1...
近日!红龙poker辅助平台,... 近日!红龙poker辅助平台,德扑之星有透视辅助吗,总是存在有挂(的确有挂)1.德扑之星有透视辅助吗...
值得注意的是!hhpoker到... 值得注意的是!hhpoker到底可以作弊吗,德扑之星透视软件免费入口官网,好像存在有挂(有挂助手)1...
教程辅助挂!pokemmo脚本... 教程辅助挂!pokemmo脚本手机版,德普之星透视辅助软件下载,果然真的有挂(了解有挂)1、德普之星...
黑科技代打!约局吧怎么看有没有... 黑科技代打!约局吧怎么看有没有挂,德普之星透视辅助软件,确实真的是有挂(有挂讲解)德普之星透视辅助软...