Delete a Message or a List of Messages

Standard

You will need the GetBind() method in order to use this code

This method will delete a message based in a Message Unique ID and move it to deleted folders, you can change it for your needs

/// <summary>
/// Deletes the message.
/// </summary>
/// <param name="messId">The mess id.</param>
public static bool DeleteMessageByID(string messId)

{
   
Item mess = Item.Bind(GetBinding(), messId);
   
EmailMessage message = mess as EmailMessage;
   
if (message == null) return false;
   
message.Delete(DeleteMode.MoveToDeletedItems);
   
return true;
}
 

This method will delete a List of messages based in a Message Unique ID that you pass in the List<String> and move it to deleted folders, you can change it for your needs

/// <summary>
/// Deletes the message list.
/// </summary>
/// <param name="messId">The mess id.</param>
public static bool DeleteListOfMessagesByID<string> messId)

{
   
foreach (EmailMessage message in
       
messId.Select(messIdList => Item.Bind(GetBinding(), 
           
messIdList)).Select(mess => mess as EmailMessage))

   
{
       
if (message == null) return false;
       
message.Delete(DeleteMode.MoveToDeletedItems);
   
}
   
return true;
}

 

I you think this helped you, please take 10 second’s and respond to the question in the side bar, Thanks.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s