JavaMail 交换身份验证
我正在尝试使用 JavaMail 从我的应用程序中使用 Exchange 身份验证来执行此操作。有人可以给我指导吗? 身份验证后,我需要发送邮件,这是我使用 JavaMail 的主要原因。 我发现的所有链接都讨论了与此相关的问题,但我认为这对于 Java 来说一定是一项简单的任务。 提前致谢。
I'm trying to use Exchange authentication from my app using JavaMail to do this. Could some one give me a guide to do this?
After authentication I need to send mails that's the main reason that I'm using JavaMail.
All the links that I found talks about problems with this but I think this must be an easy task to do from Java.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
这是一个好问题!我已经解决了这个问题。
首先,您应该导入 jar
ews-java-api-2.0.jar
。如果你使用maven,你可以将以下代码添加到你的pom.xml
中其次,你应该新建一个名为
MailUtil.java
的java类。一些Exchange服务器不会启动<默认情况下为 code>SMTP 服务,因此我们使用Microsoft Exchange WebServices(EWS)
而不是SMTP
服务。MailUtil.java
如果您想了解更多详细信息,请参阅 https ://github.com/OfficeDev/ews-java-api/wiki/Getting-Started-Guide
It is a good question! I have solved this issue.
First, you should import the jar
ews-java-api-2.0.jar
. if you use maven, you would add the following code into yourpom.xml
Secondly, you should new java class named
MailUtil.java
.Some Exchange Servers don't startSMTP
service by default, so we useMicrosoft Exchange WebServices(EWS)
instead ofSMTP
service.MailUtil.java
if you want to get more detail, pls refer to https://github.com/OfficeDev/ews-java-api/wiki/Getting-Started-Guide
下面的示例在 Exchange 服务器上运行良好:
The below example works fine here with Exchange servers:
对我有用:
此代码基于随 java 邮件下载而提供的示例代码。
Works for me:
This code is based on the sample code arrives with the download of java mail.
Microsoft 发布了用于连接 Exchange Web Service 的开源 API
https://github.com/OfficeDev/ews -java-api
Microsoft released an open sourced API for connecting to Exchange Web Service
https://github.com/OfficeDev/ews-java-api
Exchange默认情况下不会启动SMTP服务,因此我们无法使用
SMTP协议
连接到Exchange服务器并尝试发送电子邮件。 BalusC 可以与上面的代码一起正常工作,因为您的邮件服务器管理员在 Exchange 上启用了 SMTP 服务。而在大多数情况下 SMTP 被禁用。我也在寻找解决方案。这是我发现的最好的答案,但多么令人沮丧就是你必须在60天后付款。
Exchange does not start SMTP service by default, so we can't use
SMTP protocol
to connect to Exchange server and try to send email. BalusC can work fine with the above code because your mailserver administrator enabled SMTP service on Exchange.while in most cases SMTP is disabled.I am also looking for solution.This is the best answer among what i have found, but what a frustration is that you have to pay for it after 60 days.
某些 Exchange 服务器未启用 smtp 协议。
在这些情况下,您可以使用 DavMail。
Some Exchange servers don't have smtp protocol enabled.
In these cases you can use DavMail.
尝试了 ews-java-api,正如 Populus 在之前的评论中提到的那样。它是在 Java SE 环境下使用 jdk1.6 完成的,并且效果非常好。
这些是我必须与我的示例关联的库:
希望有帮助。
Tried the ews-java-api, as mentioned by Populus on a previous comment. It was done on a Java SE environment with jdk1.6 and it works like a charm.
These are the libs that I had to associate with my sample:
Hope it helps.
上面建议的软件包基本上已经报废了。
从 https://github.com/OfficeDev/ews-java-api
7 月开始2018 年 19 日,Exchange Web Services (EWS) 将不再接收功能更新。虽然该服务将继续接收安全更新和某些非安全更新,但产品设计和功能将保持不变。此更改也适用于 Java 和 .NET 的 EWS SDK。更多信息请参见:https://developer.microsoft.com/en-us/graph/blogs/upcoming-changes-to-exchange-web-services-ews-api-for-office-365/
The package suggested above is essentially at end of life.
From https://github.com/OfficeDev/ews-java-api
Starting July 19th 2018, Exchange Web Services (EWS) will no longer receive feature updates. While the service will continue to receive security updates and certain non-security updates, product design and features will remain unchanged. This change also applies to the EWS SDKs for Java and .NET. More information here: https://developer.microsoft.com/en-us/graph/blogs/upcoming-changes-to-exchange-web-services-ews-api-for-office-365/
已解决
只需将以下内容添加到您的 pom.xml 依赖项中,
似乎 JAVA 11+ 中缺少 jaxws-api
SOLVED
Just add the follow to your pom.xml dependencies
seems that jaxws-api is missing in JAVA 11+