Solved

Customising Outlook Web Access - Accessing Mail Message Properties

Posted on 2006-07-07
12
424 Views
Last Modified: 2011-10-03
Hi,

I've written a custom program for Outlook and have been asked if it's possible to provide the same features via Outlook Web Access. I understand (I think) how to customise the toolbar, but what I need to do is be able to access the properties of the mail message the user currently has selected. Is this possible via OWA?

If it's not fully, is there any way to at least get some kind of reference to the message, so that it could then be looked up on the Exchange server via other means? The web application won't be far from the Exchange box, so I could guarantee that it would have full access to the network.

Can someone tell me whether what I am trying to achieve is possible. If not, why not? If yes, with a code sample of how to go about getting at the message properties.

Thanks for your help.
0
Comment
Question by:jonnyboy69
  • 7
  • 5
12 Comments
 
LVL 31

Expert Comment

by:LeeDerbyshire
ID: 17057913
I've done a sample add-in that allows you to view the Internet Headers of the selected message.  It adds am item to the left-click OWA context menu.  If you compare the supplied files with the originals, you will see how it was done, including how to get the reference to the selected message.  You can get the files from here:

www.leederbyshire.com/info.asp
0
 

Author Comment

by:jonnyboy69
ID: 17067510
Hi Lee,

Thanks for the response. I've taken a quick look at the code and I don't think it helps me much, but Javascript is not my forte so maybe i'm missing something!

I should probably explain exactly what I need, and then you can tell me if it points me in the right direction ...

I need to be able to access all mail message properties, not just internet headers ... so body, subject, sender and so on ...

I need to get them server side, so I can save them to a SQL database. So client side doesn't help me much.

If I can't get them directly from OWA, is there a handle to the message I can get from it, which I could then use to get the properties from Exchange server? (and if so, how do I do this).

Hope that makes sense. In the code, I noticed a call to a getSelectedMessageURL function. Maybe this could provide the handle i'm looking for?
0
 
LVL 31

Expert Comment

by:LeeDerbyshire
ID: 17067543
I see.  It gets trickier, then.  I just assumed you wanted to extend OWA a bit, and was wondering where to start.  There's probably a way to do what you want, but a little more detail is needed.  Do you want the server to save the message details when the user simply selects a message in the listing, or do you want the user to consciously initiate the action somehow, from  the context menu, perhaps?  Or does the user need to actually open and read the message?
0
 

Author Comment

by:jonnyboy69
ID: 17077282
Sorry Lee, busy day ...

The user will initiate the action from a button on the toolbar. I then want to be able to respond to that event server side preferably in ASP.NET ... or anything else. I have control over the server, so can rely on components being installed there. Once I get that click event, i'd like to be able to access the properties for the message they selected. Whether that is directly from OWA or via some kind of handle that gets me the message in Exchange (CDOEXM?).

Thanks for your help :)
0
 
LVL 31

Expert Comment

by:LeeDerbyshire
ID: 17079759
It would be easier if you could use the context menu, at least for now, since then we can simply modify the .js files from my web site that you already have.  We can add a toolbar button later, if you like, but I've never done that in OWA 2003 yet.

I haven't used ASP.NET yet, so for now it will need to be just ASP/VBScript on the server side.

If you have only one Exchange server, then we can use ADO, something like this:

http://www.msexchange.org/articles/Put_Your_Exchange_2000_Mailbox_On_The_Web_With_ADO.html
0
 

Author Comment

by:jonnyboy69
ID: 17082831
Hi Lee,

OK, i've written some code that allows me to retrieve a particular message and I can see that I can access pretty much any property of the message I need ... great.

In order to open the message though, I need to know the URL for it, so if i'm right, it's something in the form of: http://localhost/exchange/<mailboxname>/Inbox/Test Message.EML

So, I just need to know how to get this URL server-side, based on the currently selected message in OWA. If it's possible to get this via client-script and then throw it to the back-end via querystring, that would be great.

Context menu isn't a problem. I think i've found some sample code for modifying the toolbar.

One other thing. If I use ExOleDb to get at the messages as I am doing, it needs to be on the same machine as the Exchange Server and then I can access any mailbox. However, if I try using a URL like the one above I get an access denied error. I know how to workaround that by using a "file" URL, e.g. file://./backofficestorage/admin/<domain>/MBX/<mailboxname>/Inbox/Test Message.EML, the difference being that I specify "admin" in the URL and I can access any mailbox. Do you know the equivalent for the http URL? Presumably I could use "file" if necessary, but as it's a web app it made more sense to me to keep it all web.

Thanks again


0
Want to promote your upcoming event?

Are you going to an event? Are you going to be exhibiting at a tradeshow? Talking at a conference? Using a promotional banner in your email signature ensures that your organization’s most important contacts stay in the know and can potentially spread the word about the event.

 
LVL 31

Expert Comment

by:LeeDerbyshire
ID: 17084246
You'll need to use JavaScript to send a GET request to the server, and pass the URL that way.  Here's the first step.  In your util_View.js file, add three bits of code (shown below), clear your cache, and check for a new context item titled TEST.  Oh, make a copy of the existing file first.

Bit 1. Look for a function named cmCreate.  Right near the end, there is a block of code starting with if (!g_fIsPublic) , and ending with break; .  Just before the break, insert a line line this:

  idVwMenu.add("TEST", "TEST");

Bit 2. Look for a function named actionHandler .  Right near te end, before the default action add this:

  case "TEST":
    TEST();
    break;

Bit 3. Right at the end of the file insert all this:

var objMSXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");

function TEST()
{
  try
  {event.returnValue = false; event.cancelBubble = true;}
  catch(e){}
  var strURL = getSelectedMessageURL();
  objMSXMLHttp.Open("GET", "http://w2k3s1/Test.asp?strURL=" + escape(strURL), true);
  objMSXMLHttp.SetRequestHeader("Content-type", "text/xml");
  objMSXMLHttp.OnReadyStateChange = TEST2;
  objMSXMLHttp.Send("");
}

function TEST2()
{
  if(objMSXMLHttp.readyState == 4)
  {
    objMSXMLHttp.OnReadyStateChange = TEST3;
    strResponseText = objMSXMLHttp.ResponseText;
    alert(strResponseText);
  }
}

function TEST3(){return;}
0
 
LVL 31

Expert Comment

by:LeeDerbyshire
ID: 17084257
Oh, by the way, that w2k3s1 bit is my own server name - you'll need to use your own.
0
 

Author Comment

by:jonnyboy69
ID: 17091383
Looks good. Have integrated that and confirmed that it works OK.

The one issue is the one about permissions I highlighted earlier when i'm actually trying to use it to get message properties from Exchange. I can't access the message using the http URL, it doesn't provide me with access. I guess I could by changing the URL to the "file" type, but is there an http equivalent that you know of?

Code i'm using at the moment to get message details is as follows:

        If Not Me.IsPostBack Then
            Dim sMsgURL As String = Request.QueryString("msgid")
            litURL.Text = sMsgURL
            If Len(sMsgURL) > 0 Then
                '-- Have to get the mailbox url from the message url
                Dim sMailboxURL As String
                sMailboxURL = Mid(sMsgURL, 1, InStr(InStr(sMsgURL, "exchange/") + 9, sMsgURL, "/"))
                '-- Open connection to the mailbox
                Dim oCn As ADODB.Connection = New ADODB.Connection
                oCn.Provider = "ExOLEDB.DataSource"
                oCn.Open(sMailboxURL)
                '-- Get the message
                Dim oMsg As New CDO.Message
                oMsg.DataSource.Open(sMsgURL, oCn, ADODB.ConnectModeEnum.adModeReadWrite, ADODB.RecordCreateOptionsEnum.adFailIfNotExists, ADODB.RecordOpenOptionsEnum.adOpenSource, "", "")
                '-- Prove that we're looking at it
                litSubject.Text = oMsg.Subject
                litBody.Text = oMsg.HTMLBody
            End If
        End If

Comes up with "Access is denied" when trying to open the message ("oMsg.DataSource.Open" etc) regardless of the mailbox being accessed. As I said, I guess it's deriving it's permissions from the IIS account.

Once I can open the message, we're done.

Thanks again
0
 
LVL 31

Accepted Solution

by:
LeeDerbyshire earned 500 total points
ID: 17091491
You will need to make sure that your server-side script is protected by Authentication.  Try Integrated and Basic (both, or separately), and see if it helps.  You will not be able to access a mailbox with a script that allows Anonymous Access via IIS.  At least, you ~shouldn't~ be able to.  Unless you can assign some kind of service account credentials to your server-side components.

I can't think of any reason right now why file:// access should work where http:// doesn't.  Unless you are using forms-based authentication, or requiring SSL (which means you need to use https, instead).

I'm not sure what this line is doing:
  sMailboxURL = Mid(sMsgURL, 1, InStr(InStr(sMsgURL, "exchange/") + 9, sMsgURL, "/"))
You should be able to use the URL as provided by the querystring without changes.
0
 

Author Comment

by:jonnyboy69
ID: 17092175
Yup, you're right. I needed Integrated security setup in IIS and anonymous access disabled. I then had to add <identity impersonate="true" /> to my web.config.

That code is working fine now and i'm getting the message details for the selected message in any mailbox I care to login to.

Great ... thanks a lot for your help :)
0
 
LVL 31

Expert Comment

by:LeeDerbyshire
ID: 17092197
No problem.  It was in interesting task, and I'm glad it works.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
In this video we show how to create a Contact in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Contact ta…
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now