We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Manipulate the mail with old mail conversation


I am new in this forum.I hope this is right place to ask my question.

I have a case that we are using Enterprise content management solution to manage the documents & business process so here when we create the business process users used to send the mail.

Here the business case in the insurance company(Z) that X company have a policy with Z company , X company any new employee joined they will send the mail to Z company then Z company will fill the form for business process in ECM system then ECM system send the mail to X Company,here the problem is when ever sending the mail it is going as an new email.My requirement here is X company they will reply from Outlook so they will just send the reply on same mail but Z company via ECM system so they can not reply the same mail so please advise me is there any way whenever sending the mail from ECM system it should not go as an new mail it should go with old mail conversation.

Please advise me how i can achieve this & how I can live chat with the technical people .


Thank you for writing to Aspose Support team.

Could you please share with us if you are using Aspose.Email API in your Enterprise content management? At Aspose.Email forums, we provide support to our customers who use our APIs in their applications and come across issues that need to be fixed. Please let us know further details for further assistance in this regard.


Thanks for your reply.

Hopefully we are going to purchase your API library ,right now we are trying to use the trail version because we have to verify that your API capable to do our business case.that what i shared my business case .

please let me know can i achieve my business case using your library


Yes, sure this requirement can be fulfilled using our library.

In this case, you need to search the first mail from X-company using some criteria. Once the mail is found, prepare a reply and send back to X-company. Following is a sample code which can be used to send reply after searching the mail.

const string mailboxUri = "https://z-company-exchange.domain.com/ews/Exchange.asmx";
const string domain = @"";
const string username = @"z-company-user";
const string password = @"password";

NetworkCredential credentials = new NetworkCredential(username, password, domain);

using (IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials))
        // Set conditions
        ExchangeQueryBuilder builder = new ExchangeQueryBuilder();
        MailQuery query = builder.GetQuery();
        //Here any random query can be used
        MailQuery query2 =
            builder.From.Contains("Hint 1 for From address"),
            builder.From.Contains("Hint 2 for From address")),
            builder.To.Contains("Hint 1 for To address")),
            builder.To.Contains("Hint 2 for To address")),
            builder.Subject.Contains("Hint 1 for Subject")),
            builder.Subject.Contains("Hint 2 for Subject"));
        ExchangeMessageInfoCollection messageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri, query);
        if (messageInfoCol.Count > 0)
            Console.WriteLine("message found in Inbox");
            Console.WriteLine("Error! No message in Inbox");
        //Generate the reply message with image
        MailMessage msgReply = new MailMessage();
        msgReply.HtmlBody = "**Html body with an image.** Here is an embedded image.";
        LinkedResource logo = new LinkedResource("CompanyLogo.png", MediaTypeNames.Image.Png);
        logo.ContentId = "CompanyLogo";
        msgReply.IsBodyHtml = true;
        //Set From, To, ReplyToList
        msgReply.From = new MailAddress("z_company@domain.com");
        //Send the reply to the old mail instead of sending new mail
        client.Reply(msgReply, messageInfoCol[0]);
    catch (Exception ex)
        Console.WriteLine("Error in program");

You may also visit our article about managing the conversations 1 for getting more information about the conversation threads in your inbox.


Thanks for your replay.

You send the sample code using Exchange server web service but here i am using account type is IMAP,Kindly send me the code using IMAP & find an attachment for more clearance.

Let me do the testing for my scenerio after code received.
Much appreciated your assistance.


Please refer to the following code sample that:

  1. Retrieves messages from inbox of a folder using the API’s ImapClient query builder
  2. Create a reply message for the retrieved message of interest
  3. Save the message to disc or send it using the API’s Smtp or EWS client.

Please try it at your end with your desired scenarios and feel free to write to us if you have any further query in this regard.

Sample Code

ImapClient client = new ImapClient(“domain.host.com”, “username”, “password”);
client.SecurityOptions = SecurityOptions.Auto;

//lets find the email sent from company-x
ImapQueryBuilder builder = new ImapQueryBuilder();
MailQuery query = builder.GetQuery();

//Get the messages from server that meet the X-Company criterion from Inbox
ImapMessageInfoCollection msgsColl = client.ListMessages(query);

//Lets say that we find the message at index 0. We need to first fetch this message
MailMessage emlFromCompanyX = client.FetchMessage(msgsColl[0].UniqueId);
//Let’s build the reply message for this message
ReplyMessageBuilder replybuilder = new ReplyMessageBuilder();

// Set ReplyMessageBuilder Properties
replybuilder.ReplyAll = true;
replybuilder.AdditionMode = OriginalMessageAdditionMode.Textpart;
replybuilder.ResponseText = “

Dear Friend,

I want to do is introduce my co-author and co-teacher.

<a href=“www.google.com”>This is a first link

<a href=“www.google.com”>This is a second link”;

MailMessage replyMail = replybuilder.BuildResponse(emlFromCompanyX);

//Now you can either save this message to disc
replyMail.Save(“ReplyToTest.eml”, Aspose.Email.Mail.SaveOptions.DefaultEml);

//or send it using Aspose.Email’s Smtp or EWS client
SmtpClient smtpClient = new SmtpClient(“smtp.domain.com”, 2234, “username”, “password”);


Really thanks for your support & sample code.

I have tested that it was working amazing.here i have to know how i can send the new mail when searching the mail based on some criteria count =0 .kindly share the piece of code in order to do the testing.


If result of criteria count = 0, then it means there is no email received from Company-X. In this case, you can not reply to an existing message but create and send a new message as shown in the following code sample.

Sample Code

MailMessage eml = new MailMessage("from@domain.com", "to@domain.com", “Subject”, “Body”);

//Add attachments if you want

//Add inline images if you want

StmpClient client = new SmtpClient(“[host.domain.com](http://host.domain.com/)”, 234, “username”, “password”);



x- company will send the mail to z insurance company after that z company will generate ticket no so when i reply to the x company i have add this ticket not into the subject .please provide the sample how i can change the subject while reply.

please explain following question below,

1) how i can get new arrived mail along with attachments with full path in order to push them into ECM System once i moved it should be flagged because next time it should not come.
2) I want to know the pricing structure
3) Where i can the full documentation about this.


In order to change the subject for adding the token number to it, use the MailMessage.Subject property as follow:

fetchedEml.Subject = “Token number from Z company”;

1. You need to retreieve only unread messages from the server and then mark them as read. Please have a look at the following code sample for your reference.

Sample Code

ImapClient client = new ImapClient(“[exchange.domain.com](http://exchange.domain.com/)”, “username”, “password”);


//Filter only those messages which are unread

ImapQueryBuilder builder = new ImapQueryBuilder();


ImapMessageInfoCollection msgsColl = client.ListMessages(builder.GetQuery());

Console.WriteLine("Unread messages: " + msgsColl.Count);

//now process each message and change its flag to read

foreach(ImapMessageInfo msgInfo in msgsColl)


//fetch message and change its subject… do your work of saving to ECM

MailMessage eml = client.FetchMessage(msgInfo.UniqueId);

eml.Subject = “Append your ticket number here”;

//Now send to X-Company or whosoever using SmtpClient

//Now mark the message as read so that it is not retrieved next time

client.ChangeMessageFlags(msgInfo.UniqueId, ImapMessageFlags.IsRead);


2. You can post on Aspose.Purchase forum to get further information about your needs from our business team.

3. We have complete documentation about the API and its components. Please visit the documentation of Aspose.Email for .NET for getting further information in this regard.

Please feel free to write to us if you have any further inquiry in this regard. We’ll be pleased to assist you further.