Cancelling ItemSend event removes signature tag?

J

Josh

I have code that verifies the sending account before a message is
sent. So in the Application_ItemSend event, it will display "Are you
sure you want to send using account-name." If you click no, it will
set Cancel=True. This gives the user the opportunity to change to the
correct account. The problem is that this process somehow removes the
special bookmark used for the signature. So, even if I manually update
the account using the account dropdown, the signature won't update. As
further proof, if I go to Insert -> Signature and select one, it will
insert a second signature on the email (as opposed to replacing the
existing one).

Any thoughts on why this is happening or how to prevent it?

Thanks,
Josh
 
K

Ken Slovak - [MVP - Outlook]

Outlook version and email editor used?

In general that event is way too late to change signatures. You would have
to do it before the item is sent to the email transport, or you'd have to
find the bookmark and change the signature yourself in code based on the
sending account.
 
J

Josh

Sorry, using Outlook 2007. I'm not actually trying to change the
account/signature in the ItemSend event. I'm just doing some confirmation and
then sometimes canceling the send. Once i cancel, I'm looking at the unsent
email in Outlook again and just trying to manually update the
account/signature.

How can I capture the event of someone trying to send an email before it
gets to the ItemSend event? If there's not a way of doing that, how could I
modify the signature using bookmarks? As I mentioned, it seems to me that
something about calling the ItemSend event and then canceling it blows away
the bookmark, as Outlook can't even modify the signature through the GUI
after that occurs.

Thanks,
Josh
 
K

Ken Slovak - [MVP - Outlook]

You said you were using the Application_ItemSend() event, try using the
Item.Send() event which occurs before Application_ItemSend(). If that
doesn't work then you can't do what you want to do.
 
J

Josh

Ken,

Thanks for the reply. I'm sorry but I'm not sure how to handle the
Item.Send() event. I read some of your other posts, like this one:
1. Declare at class level an ItemEvents_Event object, say _apptEvents:
private Outlook.ItemEvents_Event _apptEvents;

Then instantiate the event handler so:
_apptEvents = (Outlook.ItemEvents_Event)_appt;
_apptEvents.Send += new Outlook.ItemEvents_SendEventHandler(myHandler);

but I don't see the Outlook.ItemEvents_Event in intellisense.

Thanks,
Josh
 
K

Ken Slovak - [MVP - Outlook]

That example uses C#, from what you've posted I assume you are using VBA
code, which is completely different. In that case the item will directly
expose the Send() event, so if you have a MailItem as objMail then
objMail.Send() will refer both to the Send() method and the Send() event.

For VBA code you would need to declare your item object (objMail say)
WithEvents so you can handle events on that item.
 
J

Josh

Ken, thanks for the reply. I did as you said, and it is capturing the
objMail_Send event prior to Application_ItemSend. However, it is still
experiencing the same problem with the signature not updating/not being
updateable.

Also, I have in ThisOutlookSession:
Public WithEvents objMail As MailItem
Private Sub Application_ItemLoad(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
Set objMail = Item
End If
End Sub

Is this the correct place to put this code? How do I handle if multiple
message are opened at once? Seems like it could get a handle to the wrong
item when sending.

-Josh
 
K

Ken Slovak - [MVP - Outlook]

That's the correct location. For multiple open Inspectors or items you can
use a collection to hold them and a unique Key value for each one. I usually
use a special wrapper class that declares any item or Inspector objects I'll
need along with the event handlers for the specific item. Then each item's
events fire only in that class. The collection keeps the class alive until
it's no longer needed, you just remove it from the collection when the item
or Inspector is closed.

As I mentioned, that might not work since the signature stuff is only done
by Outlook when a new item is opened/replied to/forwarded. For anything else
it becomes a matter of finding the existing signature and replacing it
yourself with the desired one using string functions.
 
J

Josh

OK, I suppose I could setup all my signatures to have some special character
combination at the start and end so I can remove the old signature and
replace with the new. So the question becomes, how do I write this function:

Private Function GetNewMessageSignatureFromAccount(inSendUsingAccount) as
string

'Take in an account and retrieve the signature to use for new messages

End Sub
 
J

Josh

Ha, I didn't intend for it to be. How do I get the new message signature text
stored in outlook associated with a given account?
 
K

Ken Slovak - [MVP - Outlook]

That's in an undocumented section of the registry under the email accounts.
How you'd parse that out I have no idea.
 

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