mailItem.HTMLBody should retrieve only current text

N

Nagaraj

while replying to messages, when I use mailItem.HTMLBody I am getting entire
body including previous messages. I want to get only current entered new text
but not previous messages. Can anyone know how to do it in C#
 
K

Ken Slovak - [MVP - Outlook]

Get the previous message that's being replied to and find the text between
the <body> and </body> tags. Then get the current reply message and get the
same from there. Do a diff on the two and what's left is the new text.
 
D

Dmitry Streblechenko

What would happen if the user repling to a message makes edits to the
original message body?
I do it all the time.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
N

Nagaraj

Thank you Ken for your reply.

My actual requirement is I already have some message replied to me. Whenever
I reply back to him I want to display (company signature) immediately after
new text which i reply to him.

But what is happening is the signature is displayed after entire text
(current text and previous message).

My current code
mailItem.HTMLBody = mailItem.HTMLBody + adContent.text;

where adContent.text is the company signature.

My requirement is i want to display company signature immediately after my
reply text but not at end of entire message( current + previous messages). Do
you have any C# code to do this?

Thanks
is
 
K

Ken Slovak - [MVP - Outlook]

You will have to do what I said, any code I have for something like that is
so customized for specific clients it wouldn't do you much good. Find the
original text within the <body> </body> tags and the new text in the reply
message and find where the new text was added to the old text. You might
also have to parse the text to remove any existing signatures if they are
present in the text.
 
N

Nagaraj

Hello Ken,

I have the following text in the original text within the body


<div>please see below. i will send another one where its coming on top of
the email.</div><div><br></div><div>raghu</div><div style="font-family:times
new roman, new york, times, serif;font-size:12pt"><br><div
style="font-family:times new roman, new york, times,
serif;font-size:12pt"><font size="2" face="Tahoma">----- Forwarded Message
----<br><b><span style="font-weight: bold;">From:</span></b> Steve Waterhouse
<[email protected]><br><b><span style="font-weight:
bold;">To:</span></b> (e-mail address removed)<br><b><span style="font-weight:
bold;">Sent:</span></b> Thursday, March 5, 2009 3:22:01 PM<br><b><span
style="font-weight: bold;">Subject:</span></b> FW: test<br></font><br>



new text message contains


<div class=Section1>

<p class=MsoNormal><span
style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>fwd<o:p></o:p></span></p>

<p class=MsoNormal><span
style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<div>

<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in
0in'>

<p class=MsoNormal><b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> sridhar
[mailto:[email protected]] <br>
<b>Sent:</b> Friday, March 06, 2009 2:36 AM<br>
<b>To:</b> Nagaraj<br>
<b>Cc:</b> Vikram Rayabhari<br>
<b>Subject:</b> Fw: test<o:p></o:p></span></p>

</div>

</div>

<p class=MsoNormal><o:p> </o:p></p>

<div>

<div>

<p class=MsoNormal>please see below. i will send another one where its coming
on top of the email.<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><o:p> </o:p></p>

</div>


My problem is I am unable to search the text in the original text

<div>please see below. i will send another one where

in the new message text because in the new text <p class=MsoNormal> tag is
attached to the modified text as follows

<div>

<p class=MsoNormal>please see below. i will send another one where its coming


Can you suggest me how to get the index of 'please see below' in the new
message text


Thanks





Nagaraj Tadipatri
 
K

Ken Slovak - [MVP - Outlook]

If you are specifically looking for "please see below" then it's easy to
find that text.

Outlook will rewrite your HTML, and how it's rewritten depends also on what
email editor is being used. If necessary you have to experiment with that
and possibly set up different tests depending on whether or not WordMail is
being used and what version of Outlook the code is running on.

One trick you can use is to get the text without all the HTML tags by
reading the Body property to get the plain text equivalent. That makes it
easier to find the end of the previous message, once you have that you can
search for the equivalent text in the HTMLBody. Then you apply logic that
starts at that position and works backwards or forward to find the enclosing
tags for that section.




Nagaraj said:
Hello Ken,

I have the following text in the original text within the body


<div>please see below. i will send another one where its coming on top of
the email.</div><div><br></div><div>raghu</div><div
style="font-family:times
new roman, new york, times, serif;font-size:12pt"><br><div
style="font-family:times new roman, new york, times,
serif;font-size:12pt"><font size="2" face="Tahoma">----- Forwarded Message
----<br><b><span style="font-weight: bold;">From:</span></b> Steve
Waterhouse
<[email protected]><br><b><span style="font-weight:
bold;">To:</span></b> (e-mail address removed)<br><b><span style="font-weight:
bold;">Sent:</span></b> Thursday, March 5, 2009 3:22:01 PM<br><b><span
style="font-weight: bold;">Subject:</span></b> FW: test<br></font><br>



new text message contains


<div class=Section1>

<p class=MsoNormal><span
style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>fwd<o:p></o:p></span></p>

<p class=MsoNormal><span
style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<div>

<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in
0in
0in'>

<p class=MsoNormal><b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> sridhar
[mailto:[email protected]] <br>
<b>Sent:</b> Friday, March 06, 2009 2:36 AM<br>
<b>To:</b> Nagaraj<br>
<b>Cc:</b> Vikram Rayabhari<br>
<b>Subject:</b> Fw: test<o:p></o:p></span></p>

</div>

</div>

<p class=MsoNormal><o:p> </o:p></p>

<div>

<div>

<p class=MsoNormal>please see below. i will send another one where its
coming
on top of the email.<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><o:p> </o:p></p>

</div>


My problem is I am unable to search the text in the original text

<div>please see below. i will send another one where

in the new message text because in the new text <p class=MsoNormal> tag is
attached to the modified text as follows

<div>

<p class=MsoNormal>please see below. i will send another one where its
coming


Can you suggest me how to get the index of 'please see below' in the new
message text


Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top