ulluoink ulluoink - 1 year ago 165
C# Question

open an existing email with outlook from a website

We are saving some Emails from a specific Inbox of an Exchange Server to some kind of tracking system. User look at this tracking system by using the browser.

What I am trying to do now is to generate a link on a webpage which opens an existing email in Outlook 2010 on the client of course.

To generate this link I have all necessary information of the email/item (using Microsoft.Exchange.WebServices).

So how to do that?

ok what i have so far:
convert the ewsId (id of the mail on exchange server) from exchange server to entryid of outlook. this is done by using the ConvertId method of EWS.

now i have the problem that when i try to load the mail with outlook i get an error "element could not be opened. try again".

Answer Source

ok i found a solution an post my code here:

on the serverside (c# with exchange webservice):

    private static String GetOutlookEntryId( EmailMessage message, ExchangeService esb ) {
        AlternateId ewsId = new AlternateId( IdFormat.EwsId, message.Id.ToString(), "email.address@test.de" );
        AlternateIdBase entryId = esb.ConvertId( ewsId, IdFormat.EntryId );
        return Base64StringToHexString( ( (AlternateId)entryId ).UniqueId );

    public static String Base64StringToHexString( String base64String ) {
        byte[] bytes = System.Convert.FromBase64String( base64String );

        StringBuilder sbHexString = new StringBuilder();
        for( int i = 0; i < bytes.Length; i++ ) {
            sbHexString.Append( bytes[i].ToString( "X2" ) );
        return sbHexString.ToString();

on the client side (Internet explorer, Outlook installed, vbscript):

<script language="vbscript">
sub openMailInOutlook
    mailID = "the entry id converted from exchange id on the server side"

    set olApp = createobject("Outlook.Application")

    set session = olApp.Session
    set originalMailItem = session.GetItemFromID( mailID )


    set olNs = Nothing
    set olApp = Nothing
end sub

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download