Create a new Outlook MailItem with user's default signature

Y

yinjennytam

From the current Outlook Object model, I can't seem to find a way of knowing
whether the user has a default signature setup.

In addition, when creating a new MailItem, even though I have a default
signature setup, the new mail does not have it added automatically. Our
add-in needs to support Outlook 2000, 2002 and 2003, and I used the OOM from
Outlook 2000.

Is there any way around it or am I missing something? Thank you very much!
 
P

Peter Huang [MSFT]

Hi

One approach, I think we can call the mailitem.display method, it will
cause the signiture to be added.

Sub Test()
Dim mi As MailItem
Set mi = Application.CreateItem(olMailItem)
mi.To = "mailaddress"
mi.Subject = "hello"
mi.Display
mi.Send
End Sub

Or I think we have to add the signiture into the email body via code.
If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Y

yinjennytam

No. Calling the MailItem.Display method does not work for us. :-(

I have also tried the Outlook.Application.CreateItemFromTemplate method, but
this does not work if the user has specified Word as the email editor.

Also, when the user has set up more than one signature, how do we know which
one is the default?

Thank you
 
P

Peter Huang [MSFT]

Hi

The outlook will select the default signature we specified in the outlook's
setting, just as we click new message.
When we call the mailitem's display method, the mailitem's composing UI
will be displayed and the signature will be added automatically.
If so, I think you may try to call the mailitem's display method but not
the Send method, so that the mail composing window will not closed.

You may have a check to see if the the signature is added.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Y

yinjennytam

Thanks! I have figured out why it didn't work for me finally! I have tested
in Outlook 2002 and 2003 and it works. My question is whether it works back
in Outlook 2000?

The original problem was that I wanted to preset the MailItem.Body property
before I call MailItem.Display, and once I do that, the signature is
overwritten. If I removed this step, the default signature shows up again.
This is good.

However, I still want to know whether there is a way to preset the Body
property while keeping the signature?

Thank you very much for your help!
 
P

Peter Huang [MSFT]

Hi

If so I think we can just switfch the order of the mi.Display and mi.Body.

Sub Test()
Dim mi As MailItem
Set mi = Application.CreateItem(olMailItem)
mi.To = "mailaddress"
mi.Subject = "helo"
mi.Display
mi.Body = "This is a test!" & mi.Body
End Sub

Since Outlook 2000's object modal about MailItem is not changed, I think
that should work.
If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
K

Ken Slovak - [MVP - Outlook]

Since Outlook caches items in memory it might be necessary also to save the
item, get its EntryID, release all references to the object after setting
the .Body or .HTMLBody, then getting the item again using
NameSpace.GetItemFromID and then displaying it.
 
Y

yinjennytam

Thank you for your help. This seems to work for me but

(1) The MailItem will appear first without our message then with our message
(with OL2002 it even triggers the Outlook security prompt) :-(
(2) If I set the Body property, I will lose my formatting (signature or
stationery)
(3) Should I try setting the HTMLBody property? Does it work for all
message formats (plain, RTF or HTML)? Because it seems that when I do set
the HTMLBody property, it switches my message format from RTF to HTML, etc.

Is there a better way than doing all these?

Thank you very much
 
P

Peter Huang [MSFT]

Hi

Thanks for your quickly reply!

(1) The MailItem will appear first without our message then with our
message
(with OL2002 it even triggers the Outlook security prompt) :-(

This is the new security feature which will helps to protect again virus.

(2) If I set the Body property, I will lose my formatting (signature or
stationery)

I will research the issue and give you a reply ASAP.

(3) Should I try setting the HTMLBody property? Does it work for all
message formats (plain, RTF or HTML)? Because it seems that when I do set
the HTMLBody property, it switches my message format from RTF to HTML, etc.

The HTMLBody is used with HTML formatting.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang [MSFT]

Hi

Actually, the first problem is that that the OM doesn't handle autosigs
very well. That functionality is in Outlook's UI-type code, therefore you
theoretically need to display the item first so the autosig gets added.
However, you can also use GetInspector to force the autosig to be added:

Sub Test23232323()
Dim mi As Outlook.MailItem
Set mi = Application.CreateItem(olMailItem)
mi.To = "address"
mi.Subject = "hello"
Set oInsp = mi.GetInspector
mi.Send
End Sub

The second issue is just a limtation of the Body property.

Description of the Message or Notes field in Outlook 2002 (291153)
http://support.microsoft.com/default.aspx?scid=KB;EN-US;291153

Using HTML-formatted mail and the HTMLBody property would be preferred
approach, but of course this typically isn't realistic for an org-wide
solution where messages are in various formats (also with and without Word
as the editor)

If you still have any concern, I suggest you contact MSPSS direct to see if
they have any other idea.
http://support.microsoft.com

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
V

Vadim Rapp

I have the opposite problem with Outlook 2002.

If the user has a signature defined, and I run the following code

Set msg = objSession.GetDefaultFolder(olFolderOutbox).Items.Add("IPM.
Note.TestNote")
msg.Body = "test123"
msg.Display


Outlook adds the signature, but it adds it _before_ the text I specified. So
if the signature is

Vadim Rapp

it shows

Vadim Rapp

test123

This does not happen with regular mail message; but if you open new email,
design form, publish it as TestNote, and run the above code, it will happen.


Is there a way to for it not to add the signature, or at least, add it in
the end?

thanks,

Vadim Rapp
 
V

Vadim Rapp

I have the opposite problem with Outlook 2002.

If the user has a signature defined, and I run the following code

Set msg = objSession.GetDefaultFolder(olFolderOutbox).Items.Add("IPM.
Note.TestNote")
msg.Body = "test123"
msg.Display


Outlook adds the signature, but it adds it _before_ the text I specified. So
if the signature is

Vadim Rapp

it shows

Vadim Rapp

test123

This does not happen with regular mail message; but if you open new email,
design form, publish it as TestNote, and run the above code, it will happen.


Is there a way to for it not to add the signature, or at least, add it in
the end?

thanks,

Vadim Rapp
 
V

Vadim Rapp

I have the opposite problem with Outlook 2002.

If the user has a signature defined, and I run the following code

Set msg = objSession.GetDefaultFolder(olFolderOutbox).Items.Add("IPM.
Note.TestNote")
msg.Body = "test123"
msg.Display


Outlook adds the signature, but it adds it _before_ the text I specified. So
if the signature is

Vadim Rapp

it shows

Vadim Rapp

test123

This does not happen with regular mail message; but if you open new email,
design form, publish it as TestNote, and run the above code, it will happen.


Is there a way to for it not to add the signature, or at least, add it in
the end?

thanks,

Vadim Rapp
 
M

martin santos

For Outlook 2000:

objMI.Display
objMI.HTMLBody = strBody & objMI.HTMLBody


where objMI is the Outlook mail item object and strBody is the email body
 

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