Opening Outlook new MailItem Display from Asp.net?


J

John Scalco

Hi,
I was wondering if it's possible to open an Outlook 'new mail' dialog and
insert an attachment from an ASP.Net web page.

I'm trying to run this from the Intranet and the I do have outlook on my
desktop machine, which is where I am opening the page from, as would other
folks here.

I put together some code (C#), which works wonderfully from a winforms app,
but in the webforms when it hits the Outlook.Appliaction ol = new
Outlook.ApplicationClass();
it dies... times out with an exception "access denied"

I suspect that this might be possible, but is related to the permissions on
the site.

Is there anyway to do this?

and while I'm asking, is there anyway to determine if outlook is installed
(from a client or server) programmatically... aside from catching an
exception if it fails?

thanks for your help in advance,
Sincerely,
John Scalco
 
Ad

Advertisements

S

Sue Mosher [MVP-Outlook]

The code behind your web form is server code. To create a new mail message
that uses the user's own Outlook profile, you would need to use client-side
code (JScript unless you know everyone is using IE as their browser, in
which case you could use VBScript). A solution I've been prototyping (not
quite ready for public consumption, alas) is a custom web control that loads
the script from a .js file on the server with the RegisterClientScriptBlock
method.

A further consideration is that the Outlook.Application object is not
considered safe for scripting. Therefore, depending on the user's browser
security settings, instantiating Outlook.Application may work, trigger a
prompt (to which the user can say Yes or No), or be disabled outright. Or
Outlook may not be present on the client machine at all. Handling all these
cases is part of the work that I still need to do on my prototype, and I'm a
pretty lousy JScript programmer so it will take me a while.

The other approach to consider is using a mailto: url, but it may be hard to
get that to add an attachment unless it's from a local or mapped network
drive.

Still another choice, if you're in an Exchange environment, is to use use
your own web form to create the message and submit it via WebDAV. (Out of my
scope of knowledge, but the docs start at
http://msdn.microsoft.com/exchange/.)

If you don't care about sending via the user's Outlook profile, then use
server-side SMTP.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
J

John Scalco

Sue,
thanks for the response.

Sue Mosher said:
The code behind your web form is server code. To create a new mail message
that uses the user's own Outlook profile, you would need to use client-side
code (JScript unless you know everyone is using IE as their browser, in
which case you could use VBScript). A solution I've been prototyping (not
quite ready for public consumption, alas) is a custom web control that loads
the script from a .js file on the server with the RegisterClientScriptBlock
method.
Sounds like a neat component/solution.

I do know that the users will be using Internet Explorer. The solution is
run on an Intranet and only works with IE6 - no options. So the script side
with user profiles sounds fine to me. Could you point me to any samples?

The part I need to emphasize here is that I would want to be able to
display the Mail dialog (MailItem dialog), the window, which appearas when
you call MailItem.Display();
I need this because
1. I want to insert the document which they were viewing in the web page
into this email.
2. I would like to allow the user to be able to access their Address/contact
book so they can choose who will the mail with the image will be sent to .
A further consideration is that the Outlook.Application object is not
considered safe for scripting. Therefore, depending on the user's browser
security settings, instantiating Outlook.Application may work, trigger a
prompt (to which the user can say Yes or No), or be disabled outright. Or
Outlook may not be present on the client machine at all. Handling all these
cases is part of the work that I still need to do on my prototype, and I'm a
pretty lousy JScript programmer so it will take me a while.
On the server side of asp.net, I have not successfully been able to create a
an instance of Outlook.Application,
this is the line it dies on.

The other approach to consider is using a mailto: url, but it may be hard to
get that to add an attachment unless it's from a local or mapped network
drive.
- I have access to where the file store is, so I can read the filename.
Still another choice, if you're in an Exchange environment, is to use use
your own web form to create the message and submit it via WebDAV. (Out of my
scope of knowledge, but the docs start at
http://msdn.microsoft.com/exchange/.)
- Problem is the user may not have Exchange installed, so it's iffy. They
may not have outlook either. I need to find out a way to detect this. Maybe
I could get away with just catching an exception and saying 'outllook mail
is not installed' ???

Or would that be cheesy?
If you don't care about sending via the user's Outlook profile, then use
server-side SMTP.
I do want to use the User's profile - if it exists, but I also need access
to their address book, so they can see a list of the contacts....

Thanks for the response Sue, I appreciate it.
any other tips/suggestions woudl be appreciated.

sincerely,
John Scalco
 
S

Sue Mosher [MVP-Outlook]

If you know IE is the browser, you could use VBScript code similar to this
in your client script:

Set objOL = CreateObject("Outlook.Application")
Set objMsg = objOL.CreateItem(0)
objMsg.Attachments.Add("\\server\share\filename")
objMsg.Display

A variation would be to check if Outlook is running first. The sample at
http://www.outlookcode.com/codedetail.aspx?id=83 is for VB/VBA, not
VBScript, but you'll see how to use GetObject. You can also use
Namespace.Logon without a profile name and prompt the user to choose a
profile.

As for WebDAV, it does not require Outlook to be installed on the client or
configured in a particular way. The ASP server talks directly to the
Exchange server. That means, of course, that it needs appropriate
permissions. .

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
J

John Scalco

Sue,
thanks for the response. I tried the first option in an asp.net page in the
body of the document and it said it couldnt' create 'outlook.application'. I
made sure my trusted zones were set right for 'intranet' and they look ok.

let me look at this a little more careful and I'll ping back.

thanks for your help,
sincerely,
John Scalco
 
Ad

Advertisements

Ad

Advertisements


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