跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[程序员] 求助 Java 用 imap 收取 outlook 邮件

发表于
各位大神:

就是最基本的收取模式。
直接用邮箱和密码去收取,
但成功率很低,有时候可以,有时候就直接报
A1 NO AUTHENTICATE failed

代码如下

// 设置 Outlook 邮件服务器和协议
Properties props = new Properties();
props.setProperty("mail.store.protocol", "imap");
props.setProperty("mail.imap.host", "outlook.office365.com");
props.put("mail.imap.starttls.enable", false);
props.put("mail.imap.ssl.enable",true);
props.put("mail.debug", "true");
props.put("mail.debug.auth", "true");

// 创建会话
Session session = Session.getInstance(props, null);
session.setDebug(true);

// 连接到 Outlook 邮箱
Store store = session.getStore();
store.connect("xxxxx@outlook.com", "邮箱密码");

// 打开收件箱
Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_ONLY);

// 获取收件箱中的邮件
Message[] messages = inbox.getMessages();

for (Message message : messages) {
System.out.println("Subject: " + message.getSubject());
System.out.println("From: " + message.getFrom()[0]);
System.out.println("Content: " + message.getContent());
}

// 关闭收件箱和连接
inbox.close(false);
store.close();



按官方的说法,应该改为 oauth2.0 去收取,但做到 oauth2 还要注册应用程序,一大堆。
我看 thunderbird mozilla 的邮件客户端 去收取 outook 邮件时,也只要填写邮箱密码,然后弹出 outlook 登陆即可。不需要常规的 oauth 的客户 id,密钥之类的


求各位大神帮我指点迷津。

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.