Hi All,
Currently we are using Microsoft ews-java-api to interact with mailboxes on Office 365 and it works fine. We are trying to make switch to Aspose.Email and to use IEWSClient instead with the same connection details but we are facing an issue:
java.lang.IllegalStateException: class com.aspose.email.system.exceptions.WebException: Error: 2 (No connection could be made because the target machine actively refused it.) —> class com.aspose.email.system.exceptions.SocketException: No connection could be made because the target machine actively refused it.
The code used to connect to Office 365 EWS is:
NetworkCredential credentials = new NetworkCredential(user_name, password);
WebProxy proxy = new WebProxy(“PROXY IP”, 8080);
IEWSClient _client = EWSClient.getEWSClient(“[https://outlook.office365.com/EWS/Exchange.asmx ](https://outlook.office365.com/EWS/Exchange.asmx)”, credentials, proxy);
Any help would be appreciated. Thanks
@slobodanvukovic,
Please try the code snippet given below to connect to mailboxes on Office 365.
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/EWS/Exchange.asmx", username, password, "");
ExchangeMessageInfoCollection msgCollection = client.listMessages(client.getMailboxInfo().getInboxUri());
System.out.println("Message Count: " + msgCollection.size());
For additional information, you can visit our documentation for Aspose.Email for Java. We hope this information was useful to you. Please feel free to contact us if additional information is required.
Thank you @muhammadahmad for fast reply!
Unfortunately the code snippet that you proposed didn’t helped, the same error is thrown.
Any other ideas?
@slobodanvukovic,
Please provide us test account credentials so that we can reproduce this issue at our end and assist you further.
@muhammadahmad, thanks for fast reply!
Unfortunately I can’t provide you with test account due to my company policies.
Maybe you can give me advice of how to properly use WebProxy? I couldn’t find any sample code with WebProxy on GIT. We are using WebProxy with Microsoft ews-java-api, which works fine, and there is a possibility that proxy is the one rejecting the connection requests from Aspose.Email.
@slobodanvukovic,
Please share the code you were using to connect to Microsoft ews-java-api.
@muhammadahmad, here is the code that is working:
ExchangeService m_service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
ExchangeCredentials credentials = new WebCredentials(userName, userPassword);
WebProxy proxy = new WebProxy(“192.168.96.1”, 8080);
m_service.setWebProxy(proxy);
m_service.setCredentials(credentials);
m_service.setUrl(new URI("https://outlook.office365.com/EWS/Exchange.asmx"));
m_service.setTraceEnabled(true);
Mailbox mailbox = new Mailbox(mailboxToRead);
FolderId folderId = new FolderId(WellKnownFolderName.Inbox, mailbox);
Folder inboxFolder = Folder.bind(m_service, folderId);
@slobodanvukovic,
We are unable to reproduce the issue you mentioned. The code we used to connect to the exchange server is given below. It is using the same proxy you used and has the test account credentials for you to test.
try {
WebProxy proxy = new WebProxy("192.168.96.1", 8080);
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/EWS/Exchange.asmx", "aspose.test2@asposetest.onmicrosoft.com", "Dop50905", proxy);
ExchangeMessageInfoCollection msgCollection = client.listMessages(client.getMailboxInfo().getInboxUri());
System.out.println("Message Count: " + msgCollection.size());
for (ExchangeMessageInfo msgInfo : msgCollection) {
String strMessageURI = msgInfo.getUniqueUri();
// Now get the message details using FetchMessage()
MailMessage msg = client.fetchMessage(strMessageURI);
// Display message details
System.out.println("Subject: " + msg.getSubject());
System.out.println("Date: " + msg.getDate());
System.out.println("From: " + msg.getFrom());
}
client.dispose();
}
catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
}
The test account contains one test email. Please try connecting to our test account. If the issue still remains, please try connecting from a different network.
@muhammadahmad,
Thanks for reply!
Unfortunately the code is not working for us. We still get the same error while trying to connect using test account. Is there a reason proxy to handle Aspose EWSClient requests in different way than for ews-java-api?
@slobodanvukovic,
Please try connecting from a different network to make sure that this is not a network related issue. Also make sure that you are using the latest version of the Aspose.Email for Java API. Please let us know the results of your testing so that we can assist you further.
@muhammadahmad
Finally we manage to perform test with network team.
The test results indicated that Aspose Email is ignoring proxy and tries to connect Outlook 365 directly even dough proxy was specified:
WebProxy proxy = new WebProxy("192.168.69.1", 8080);
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/EWS/Exchange.asmx", "aspose.test2@asposetest.onmicrosoft.com", "Dop50905", proxy);
Any idea why proxy is ignored?
@slobodanvukovic,
Thank you for your feedback. An investigation ticket has been logged in our issue tracking system as EMAILJAVA-34451 to investigate this further. We will update you here as soon as additional information is available.
The issues you have found earlier (filed as EMAILJAVA-34451) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan
Just to confirm that specified update contains fix for issue with proxy. Thanks to Aspose team!
@slobodanvukovic,
We are happy to hear that your issue has been resolved. Please feel free to contact us if additional information is required. We will be more than happy to assist you further.