Testing emails

Hi

I have to connect to my Exchange server. As a long time Aspose.Cells user, I wanted to try the emails library.

I downloaded the latest version of the dlls (5.3) and started to look around for examples.

I just cannot connect to my server and many samples are not compiling. For example ExchangeWebServiceClient seems to have been deprecated and ImapClient.Connect no longer exists apparently!

And when I try the code below, I get this error: {“The remote server returned an error: (405) Method Not Allowed.”}

Test code:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Try

Dim mailboxURI As String = “[https://192.168.13.14](https://192.168.13.14/)”

Dim uid As String = “myusername”

Dim pwd As String = “mypassword”

Dim domain As String = “mydomain,ca”

Dim client As ExchangeClient = New ExchangeClient(mailboxURI, uid, pwd, domain)

ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf RemoteCertificateValidationHandler)

Dim mailboxInfo As ExchangeMailboxInfo = client.GetMailboxInfo()

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

End Sub

Private Shared Function RemoteCertificateValidationHandler(sender As Object, certificate As X509Certificate, chain As X509Chain, sslPolicyErrors As SslPolicyErrors) As Boolean

Return True

End Function

What I need to do is to move a message from my Inbox to another folder. How can I do it?

Hi Eric,

Thank you for posting your query.

As seen from your shared code sample above, you are using ExchangeClient which is used for Exchange Server 2003 and 2007 only. For working with Exchange server 2010 and above, you need to use the IEWSClient as shown in the following code sample. The example below connects to Office365 server test account and moves an item from Inbox to Deleted Items folder. I have provided the test account credentials as well in this code sample for your testing. You can also refer to Programming with Exchange 1 section for more examples.

Regarding the obsolete members, could you please guide us towards the article links so that we can fix those.

Code:

const string mailboxUri = "https://outlook.office365.com/ews/exchange.asmx";
const string domain = @"";
const string username = @"UserONe@ASE1983.onmicrosoft.com";
const string password = @"Aspose1234";
NetworkCredential credentials = new NetworkCredential(username, password, domain);
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials);
ExchangeMessageInfoCollection msgsColl = client.ListMessages(client.MailboxInfo.InboxUri);
Console.WriteLine("**************** Listing messages from the inbox ****************");
foreach (ExchangeMessageInfo msgInfo in msgsColl)
    Console.WriteLine("Subject: " + msgInfo.Subject);
if (msgsColl.Count > 0)
{
    //move the first message to deleted items folder
    Console.WriteLine("\nMoving first message to deleted items folder...");
    client.MoveItem(msgsColl[0].UniqueUri, client.MailboxInfo.DeletedItemsUri);
}
Thread.Sleep(2000); //wait for some time
//Again list messages.. it should be 1 less now in Inbox
msgsColl = client.ListMessages(client.MailboxInfo.InboxUri);
Console.WriteLine("**************** Listing messages from the inbox ****************");
foreach (ExchangeMessageInfo msgInfo in msgsColl)
    Console.WriteLine("Subject: " + msgInfo.Subject);

Hi


Thanks for the explanation. I have been able to put a quick test.

As for the links, not really sure which one because I googled a lot this morning but I remember that the examples on Git had issues.

Hi Eric,


Thank you for sharing your feedback. We are currently in process of updating our documentation (both online and GitHub repositories) for reflecting the changes in code samples and removing obsolete code. Hopefully, these will be done soon and you’ll be able to use the examples from GitHub. If you have any further query related to Aspose.Email API, please feel free to write to us for assistance.