Deleting sent message after sending it

Hi,

I have to send auto reply emails when receiving a message in a shared mailbox and based on different reason sent the email. After the sent, I need to delete the email from the sent item folder. But when I try to delete it I get this message:

ExceptionAspose.Email.Exchange.ExchangeException: DeleteMessage failed. Response Code: ErrorCannotDeleteObject, MessageText: Object cannot be deleted.

My Code:

var replyMessage = new MailMessage

{

From = this.autoReplyAddress,

To = email.From,

HtmlBody = emailInfo.ReplyEmail,

Body = emailInfo.ReplyEmail,

Subject = "RE: " + email.Subject

};

var credential = new NetworkCredential(mailboxUser,mailboxUserPSW,mailboxDomain);

ExchangeWebServiceClient client = new ExchangeWebServiceClient(this.mailboxConnection, credential);

client.Send(replyMessage);

var sentMessages = client.ListMessages(client.GetMailboxInfo().SentItemsUri);

foreach (var sentMessage in sentMessages)

{

if (sentMessage.Subject != null && sentMessage.Subject.Equals(msgSubject))

{

client.DeleteMessage(sentMessage.UniqueUri, true);

}

}

On the client.DeleteMessage I get the exception error.

Thanks

Pierre

Hi Pierre,


Please accept my sincere apology for late reply.

I have tried to reproduce this issue here but could not succeed. I used your code to send mail by Exchange server and then observed the “Sent” folder using browser. I found the message in the sent box. Then I executed the rest of the code and observed that it was deleted successfully from the sent folder.

Now to further proceed, could you please arrange some test account on the exchange where you are testing your sample code. It will help us to re-produce the issue and assist you as much as possible.

If you plan to send the credentials, please send it via email to me. I would like to inform you that these test accounts and customer information is treated as confidential and only concerned Aspose staff members have access to it.

We are sorry for any inconvenience caused to you and thanks in advance for you cooperation.