Search and replace text from MSG file (C# .NET)

Hello Aspose,

How can I find and replace text by Aspose.email. I have a file and want to find and replace some placeholder by some text. I have attach file template “GenerateMSGAspose.msg” please see in detail.
How can I replace some placeholder like [@@…@@] by some text.
example: replace [@@firstname@@] by “David”, [@@lastname@@] by “beckham”…
GenerateMSGAspose.zip (34.6 KB)

Thank you very much!

@nguyenhungkloon,

I have shared code snippet with you. Please use following code snippet on your end and share feedback with us if there is still an issue.

MailMessage m = MailMessage.Load(“GenerateMSGAspose.msg”;
m.Body = m.Body.Replace("[@@FullName@@", “Adnan Ahmad”);
m.Save(“GenerateMSGAspose.msg”);

I have use your source code but I can not Replace. So I have create small demo and send to you. Please see “TestReplaceTextMail.zip”
TestReplaceTextMail.zip (8.6 MB)

And teach me how can I replace text in MSG file.

Thank you very much!

@nguyenhungkloon,

I have worked with MSG file shared by you. Actually, the BodyType of message is HTML. Therefore, you need to carry out replacement in HtmlBody rather than Body alone. The attached sample project will serve the purpose on your end.

TestReplaceTextMail.zip (5.7 MB)