Security Error Attempting to Create Outlook Object in .NET

G

Guest

When attempting to load an Oulook Object in ASP.Net (VB) I get the foloowing
error on the Server:

System.Security.SecurityException: Request for the permission of type
System.Security.Permissions.SecurityPermission, mscorlib, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.

Here's the code
Dim objOutlook As New Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
objOutlook = CreateObject("Outlook.Application")
objOutlookMsg =
objOutlook.CreateItem(Outlook.OlItemType.olMailItem)
With objOutlookMsg
.Recipients.Add(RecipientEmail)
.Subject = _MAIL_SUBJECT
.HTMLBody = strStaticBody
.Display()
End With
objOutlookMsg = Nothing
objOutlook = Nothing
I have a reference to the DLL
 
J

Jay B. Harlow [MVP - Outlook]

sakieboy,
Outlook is not designed to be run from an ASP.NET app!

| .Display()
Will attempt to display the outlook form on the server itself. If you are
attempting to display the user's Outlook client, then I would recommend
rethinking what you are doing as that is extremely virus like!


To simply send an email on the server I would recommend:

System.Web.Mail (.NET 1.x) :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebmail.asp

http://www.systemwebmail.com/

or System.Net.Mail (.NET 2.0) instead:
http://msdn2.microsoft.com/en-us/library/system.net.mail.aspx

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| When attempting to load an Oulook Object in ASP.Net (VB) I get the
foloowing
| error on the Server:
|
| System.Security.SecurityException: Request for the permission of type
| System.Security.Permissions.SecurityPermission, mscorlib,
Version=1.0.5000.0,
| Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
|
| Here's the code
| Dim objOutlook As New Outlook.Application
| Dim objOutlookMsg As Outlook.MailItem
| objOutlook = CreateObject("Outlook.Application")
| objOutlookMsg =
| objOutlook.CreateItem(Outlook.OlItemType.olMailItem)
| With objOutlookMsg
| .Recipients.Add(RecipientEmail)
| .Subject = _MAIL_SUBJECT
| .HTMLBody = strStaticBody
| .Display()
| End With
| objOutlookMsg = Nothing
| objOutlook = Nothing
| I have a reference to the DLL
 
C

Chris

Jay said:
sakieboy,
Outlook is not designed to be run from an ASP.NET app!

| .Display()
Will attempt to display the outlook form on the server itself. If you are
attempting to display the user's Outlook client, then I would recommend
rethinking what you are doing as that is extremely virus like!


To simply send an email on the server I would recommend:

System.Web.Mail (.NET 1.x) :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebmail.asp

http://www.systemwebmail.com/

or System.Net.Mail (.NET 2.0) instead:
http://msdn2.microsoft.com/en-us/library/system.net.mail.aspx

And to be more exact on why you are getting the error you are getting.
The asp.net user does not have permission to open outlook.

Chris
 

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