首页| 论坛| 消息
主题:EXCHANGE连接邮箱,window可以,Linux下连不上
王缘林发表于 2017-10-13 15:51
我直接附上代码,window是可以连接的;然而Linux上不知道哪里错了,就是连接不上
linux服务器是上不了外网,但是邮箱服务器是内网的,假如邮箱服务器IP地址是192.192.192.192端口是444. 账号是33212@catlbattery.com密码是xxxxxx我该怎么设置这部分代码
ExchangeCredentials credentials = new WebCredentials(user, password);
service.setCredentials(credentials);
service.setUrl(new URI(mailServer));

package test;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import microsoft.exchange.webservices.data.Attachment;
import microsoft.exchange.webservices.data.AttachmentCollection;
import microsoft.exchange.webservices.data.BodyType;
import microsoft.exchange.webservices.data.EmailMessage;
import microsoft.exchange.webservices.data.ExchangeCredentials;
import microsoft.exchange.webservices.data.ExchangeService;
import microsoft.exchange.webservices.data.ExchangeVersion;
import microsoft.exchange.webservices.data.FileAttachment;
import microsoft.exchange.webservices.data.FindItemsResults;
import microsoft.exchange.webservices.data.Folder;
import microsoft.exchange.webservices.data.Item;
import microsoft.exchange.webservices.data.ItemSchema;
import microsoft.exchange.webservices.data.ItemView;
import microsoft.exchange.webservices.data.MessageBody;
import microsoft.exchange.webservices.data.PropertySet;
import microsoft.exchange.webservices.data.SearchFilter;
import microsoft.exchange.webservices.data.SortDirection;
import microsoft.exchange.webservices.data.WebCredentials;
import microsoft.exchange.webservices.data.WebProxy;
import microsoft.exchange.webservices.data.WellKnownFolderName;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class ExchangeMailUtil {
private String mailServer;
private String user;
private String password;
private String domain;

publicExchangeMailUtil(String mailServer, String user, String password) {
this.mailServer = mailServer;
this.user = user;
this.password = password;
}
public ExchangeMailUtil(String mailServer, String user, String password, String domain) {
this.mailServer = mailServer;
this.user = user;
this.password = password;
this.domain = domain;
}
public static void main(String[] args) throws Exception {
// Outlook Web Access路径通常为/EWS/exchange.asmx

ExchangeMailUtil mailUtil = new ExchangeMailUtil("https://mail.catlbattery.com/EWS/exchange.asmx",
"3222@catlbattery.com", "xxxxxx");
// 接收邮件
ArrayList mails = mailUtil.receive(10);

for (EmailMessage mail : mails) {
System.out.println("邮件标题: " + mail.getSubject());
System.out.println("ID:"+mail.getId());
SimpleDateFormat sdf2= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String sendDate= sdf2.format(mail.getDateTimeReceived());
System.out.println("接收时间: " + sendDate);
System.out.println("发送人: " + mail.getFrom().getName() + ", 地址: " + mail.getFrom().getAddress());
System.out.println("已读:" + mail.getIsRead());
System.out.println("大小:"+mail.getSize());
//System.out.println("body:"+mail.getBody().toString());
readBodyText(mail.getBody().toString());
//SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
// 更新已读
//if (!mail.getIsRead()) {
//mail.setIsRead(true);
//mail.update(ConflictResolutionMode.AlwaysOverwrite);
//}
//System.out.println("邮件内容 :" + mail.getBody());
// 处理附件
AttachmentCollectio
下一页 (1/4)
回帖(1):
1楼:还有,EWSJAVAAPI是需要JDK多少以上的?1.5和1.6的都编译不过去

全部回帖(1)»
最新回帖
收藏本帖
发新帖