Creating a new mailItem with a signature, and a modified HTMLBody

P

Peter Reinhold

Hi All,

I am coding a OL2003 addin in C# using VS2005 and VSTO, and have my
core functionality working (a toolbar with a button, from which you are
able to create a new mailitem)

My problem is, I want to modify the HTMLBody of this new mailItem,
which I can, but this removes the signature.

If I try and use the HTMLBody from the created mail (after its been
shown, so it contains the signature), I get a security warning, which
is not acceptable for my end-users.

I've tried using Redemption, with the following code :

--
Outlook.MailItem newMail =
Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
Redemption.SafeMailItem safeMail = new Redemption.SafeMailItem();

safeMail.Item = newMail;

newMail.HTMLBody = safeMail.HTMLBody.Replace("<BODY>", mailBody)
--

But, the safeMail.HTMLBody is just empty, it does not contain the
HTMLBody of the original mailItem.

Does anyone know either how to get the current users signature so I can
append it to my HTML mail, or, how to get Redemption to properly return
the HTMLBody of the original mailItem?


Kind Regards,
Peter
 
K

Ken Slovak - [MVP - Outlook]

Try saving the Outlook MailItem before assigning it to a SafeMailItem and
see if that helps.

Why are you replacing a tag <BODY> ? Do you mean to replace all the text
between the start and end tags for body?

The signature block will be within the <BODY> </BODY> tags, not outside it.

Open a new mail item with a signature block in it and save the new blank
message. Use a MAPI viewer such as OutlookSpy (www.dimastr.com) to look at
IMessage and then PR_HTML (or use code to access HTMLBody in the VBA project
and OK the security warning) and see what the HTML actually looks like.
 
P

Peter Reinhold

Ken Slovak - [MVP - Outlook] skrev:
Try saving the Outlook MailItem before assigning it to a SafeMailItem and
see if that helps.

Saving it .. OK, will see if there's a function for that, or could you
explain what I would need to do? (Save it as a draft, or?)
Why are you replacing a tag <BODY> ? Do you mean to replace all the text
between the start and end tags for body?

I want to insert my pre-defined mail in the body, before the signature.
Open a new mail item with a signature block in it and save the new blank
message. Use a MAPI viewer such as OutlookSpy (www.dimastr.com) to look at
IMessage and then PR_HTML (or use code to access HTMLBody in the VBA project
and OK the security warning) and see what the HTML actually looks like.

PR_HTML .. Could I possibly use the GetHRProp (or what its called, I
haven't got the code in front of me right now), to get the HTML body?

I have seen what the HTML looks like with the signature in it .. If i
output (msgbox) the contents of HTMLBody after I have displayed the new
MailItem, I can get the HTML code out fine (by accepting the security
warning)

The problem is not the formatting of the mailbody, but actually getting
to the mailbody at all.

Is it possible to get the default signature via an addin?


/Peter
 
K

Ken Slovak - [MVP - Outlook]

To save an Item use Item.Save. Until you do that the HTML properties aren't
populated.

If you've looked at the HTML then you know that replacing the tag <BODY>
will do nothing for you, all it would do is replace that tag with whatever
you're adding. It would leave a hanging </BODY> tag there. And with the
signature inside the <BODY> </BODY> tags you'll end up losing your signature
anyway since you're replacing things.

You can use HRGetOneProp from Extended MAPI, but that would still do you no
good until the Outlook item is saved. Until then MAPI doesn't have the
property you want populated.

Signatures in Outlook are stored at C:\Documents and Settings\<windows
logon>\Application Data\Microsoft\Signatures. There's one in HTML, RTF and
Plain Text for every existing signature. I don't know offhand where the
setting for the default signature is stored, probably somewhere in the
registry. Changing that while running regmon or some other registry monitor
would probably show you that.




Peter Reinhold said:
Ken Slovak - [MVP - Outlook] skrev:
Try saving the Outlook MailItem before assigning it to a SafeMailItem and
see if that helps.

Saving it .. OK, will see if there's a function for that, or could you
explain what I would need to do? (Save it as a draft, or?)
Why are you replacing a tag <BODY> ? Do you mean to replace all the text
between the start and end tags for body?

I want to insert my pre-defined mail in the body, before the signature.
Open a new mail item with a signature block in it and save the new blank
message. Use a MAPI viewer such as OutlookSpy (www.dimastr.com) to look
at
IMessage and then PR_HTML (or use code to access HTMLBody in the VBA
project
and OK the security warning) and see what the HTML actually looks like.

PR_HTML .. Could I possibly use the GetHRProp (or what its called, I
haven't got the code in front of me right now), to get the HTML body?

I have seen what the HTML looks like with the signature in it .. If i
output (msgbox) the contents of HTMLBody after I have displayed the new
MailItem, I can get the HTML code out fine (by accepting the security
warning)

The problem is not the formatting of the mailbody, but actually getting
to the mailbody at all.

Is it possible to get the default signature via an addin?


/Peter
 
P

Peter Reinhold

To save an Item use Item.Save. Until you do that the HTML properties aren't
populated.

I'll try this, thanks
If you've looked at the HTML then you know that replacing the tag <BODY>
will do nothing for you, all it would do is replace that tag with whatever
you're adding. It would leave a hanging </BODY> tag there. And with the
signature inside the <BODY> </BODY> tags you'll end up losing your signature
anyway since you're replacing things.

Ofcourse said:
Signatures in Outlook are stored at C:\Documents and Settings\<windows
logon>\Application Data\Microsoft\Signatures. There's one in HTML, RTF and
Plain Text for every existing signature. I don't know offhand where the
setting for the default signature is stored, probably somewhere in the
registry. Changing that while running regmon or some other registry monitor
would probably show you that.

This is some nice info, i'll check the registry to see if I can find
anything there, but at least i'll be able to get the signature, if the
first method doesn't work.
 
P

Peter Reinhold

Plain Text for every existing signature. I don't know offhand where the
This is some nice info, i'll check the registry to see if I can find
anything there, but at least i'll be able to get the signature, if the

I found the key, its not exactly logical, but here it is

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows
Messaging
Subsystem\Profiles\Outlook\9375CFF0413111d3B88A00104B2A6676\00000003

Now i'll be able to get the current default signature, and actually
read the signature from disk :)


/Peter
 
K

Ken Slovak - [MVP - Outlook]

Actually, that does sound logical, although it's not the first place I'd
think of looking.

The default signature settings are being stored on a per Outlook profile
basis.
 

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