Here's my two cents:
First off you need to compare the origin so that you don't get your own email since whenever you send a message you get a "message received" event with yourself as origin.
Secondly the code comparing Contact.name will only work if you don't have Nickname for that person. Since Contact.Name is what they use as name and Origin might be what you use as their nickname.
Thirdly this instead of getting the contacts from the chatwindow, gets the contacts from your contact list. Might be a little longer but it'll work when you have more than one person in the chat window.
function GetContactEmail(Name) {
var Result = "";
var Contacts = Messenger.MyContacts;
var e = new Enumerator(Contacts);
for (;!e.atEnd();e.moveNext()) {
var Contact = e.item();
if(Contact.Name == Name) {
Result = Contact.Email;
}
}
return Result;
}
Just an idea
Have fun!