473,748 Members | 7,608 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Open Outlook on user machine

How can I launch Outlook on users machines when they click a button on a web
form (InfoPath)?

Thanks
Jul 3 '08 #1
23 5972
You can't.

Only client-side code can ask the client to do something. Now, you can
certainly have client code that "asks" the browser to open its default mail
client, and that *might* be Outlook, but again, it might not be.

And, for security reasons, JavaScript (the client code we're talking about)
has no abilities when it comes to the OS.

"andyoye" <an*****@nospam .comwrote in message
news:u7******** ******@TK2MSFTN GP03.phx.gbl...
How can I launch Outlook on users machines when they click a button on a
web form (InfoPath)?

Thanks

Jul 3 '08 #2
I found following from
http://forums.devx.com/showthread.ph...hlight=outlook

looks like I am missing some namespace/referneces as "Outlook.Applic ation"
could not be found.
Outlook.Applica tion objOutlk = new Outlook.Applica tion();
//Outlook
const int olMailItem = 0;
object objMail = new object();
objMail = objOutlk.Create Item(olMailItem );
//Email item
objMail.To = emaila.Text;
objMail.cc = "";
//Enter an address here To include a carbon copy; bcc is For blind carbon
copy's
//Set up Subject Line
objMail.subject = "Quality Assurance Letter";
//To add an attachment, use:
//objMail.attachm ents.add("C:\My AttachmentFile. txt")
string msg;
msg = "body test msg";
objMail.body = msg;
//Use this To display before sending, otherwise call objMail.Send to send
without reviewing
objMail.display ();
//Use this To display before sending, otherwise call objMail.Send to send
without reviewing
//Clean up
objMail = null;
"Scott M." <s-***@nospam.nosp amwrote in message
news:Op******** *****@TK2MSFTNG P04.phx.gbl...
You can't.

Only client-side code can ask the client to do something. Now, you can
certainly have client code that "asks" the browser to open its default
mail client, and that *might* be Outlook, but again, it might not be.

And, for security reasons, JavaScript (the client code we're talking
about) has no abilities when it comes to the OS.

"andyoye" <an*****@nospam .comwrote in message
news:u7******** ******@TK2MSFTN GP03.phx.gbl...
>How can I launch Outlook on users machines when they click a button on a
web form (InfoPath)?

Thanks


Jul 3 '08 #3
On Jul 3, 5:59 pm, "andyoye" <andy...@nospam .comwrote:
How can I launch Outlook on users machines when they click a button on a web
form (InfoPath)?

Thanks
I do not know why do you want to open outlook, however from
application programming side, the normal requirement is to mail
something to someone... In which case System.Web.Mail will help.

- Cnu
Jul 3 '08 #4
Add, from Office (Setup/Add/Repair) ".Net Programmability Support" (not as
load on request, but unconditionally ).

Add the reference to Office Interop to your project and the line

using Outlook=Microso ft.Office.Inter op.Outlook;

(note that this alias may help to remove ambiguity about Application and
Outlook.Applica tion)

and, to clean up, the code is missing a lot. Try adding:

objOutlk.Quit() ;
objOutlk= null;
GC.Collect();
GC.WaitForPendi ngFinalizers();
GC.Collect();
GC.WaitForPendi ngFinalizers();
More details in"Microsoft .Net Development For Microsoft Office", Andrew
Whitechapel, Microsoft Press.
Vanderghast, Access MVP

"andyoye" <an*****@nospam .comwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>I found following from
http://forums.devx.com/showthread.ph...hlight=outlook

looks like I am missing some namespace/referneces as "Outlook.Applic ation"
could not be found.
Outlook.Applica tion objOutlk = new Outlook.Applica tion();
//Outlook
const int olMailItem = 0;
object objMail = new object();
objMail = objOutlk.Create Item(olMailItem );
//Email item
objMail.To = emaila.Text;
objMail.cc = "";
//Enter an address here To include a carbon copy; bcc is For blind carbon
copy's
//Set up Subject Line
objMail.subject = "Quality Assurance Letter";
//To add an attachment, use:
//objMail.attachm ents.add("C:\My AttachmentFile. txt")
string msg;
msg = "body test msg";
objMail.body = msg;
//Use this To display before sending, otherwise call objMail.Send to send
without reviewing
objMail.display ();
//Use this To display before sending, otherwise call objMail.Send to send
without reviewing
//Clean up
objMail = null;
"Scott M." <s-***@nospam.nosp amwrote in message
news:Op******** *****@TK2MSFTNG P04.phx.gbl...
>You can't.

Only client-side code can ask the client to do something. Now, you can
certainly have client code that "asks" the browser to open its default
mail client, and that *might* be Outlook, but again, it might not be.

And, for security reasons, JavaScript (the client code we're talking
about) has no abilities when it comes to the OS.

"andyoye" <an*****@nospam .comwrote in message
news:u7******* *******@TK2MSFT NGP03.phx.gbl.. .
>>How can I launch Outlook on users machines when they click a button on a
web form (InfoPath)?

Thanks


Jul 3 '08 #5
I do want to open outlook, thats the MAIN objective here.

I ran below code:

Outlook.Applica tion outlookApp = new Outlook.Applica tion();

Outlook.MailIte m message =

(Outlook.MailIt em)outlookApp.C reateItem(Outlo ok.OlItemType.o lMailItem);

message.Subject = "Hello World";

message.Recipie nts.Add(A@aol.c om);

message.Body = "Hello. This is a test.";

I get below error when i try to run it.

System.Security .SecurityExcept ion
That assembly does not allow partially trusted callers.
at
System.Security .CodeAccessSecu rityEngine.Thro wSecurityExcept ion(Assembly
asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHa ndle rmh,
SecurityAction action, Object demand, IPermission permThatFailed)


"Duggi" <Du************ ***@gmail.comwr ote in message
news:89******** *************** ***********@u12 g2000prd.google groups.com...
On Jul 3, 5:59 pm, "andyoye" <andy...@nospam .comwrote:
>How can I launch Outlook on users machines when they click a button on a
web
form (InfoPath)?

Thanks

I do not know why do you want to open outlook, however from
application programming side, the normal requirement is to mail
something to someone... In which case System.Web.Mail will help.

- Cnu

Jul 3 '08 #6
You're missing the point. The code you show below will only work if it is
*running* on a machine with Outlook installed. Since you said "web form",
then this could will be running on a web server and there are two issues
with that:

1. Most web servers don't have Outlook installed on them, nor would you want
to as it poses a security risk.
2. Even if the server had Outlook (or the Outlook Primary InterOp Assembly -
PIA), this code runs on the server and won't do anything for the client.

-Scott

"andyoye" <an*****@nospam .comwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>I found following from
http://forums.devx.com/showthread.ph...hlight=outlook

looks like I am missing some namespace/referneces as "Outlook.Applic ation"
could not be found.
Outlook.Applica tion objOutlk = new Outlook.Applica tion();
//Outlook
const int olMailItem = 0;
object objMail = new object();
objMail = objOutlk.Create Item(olMailItem );
//Email item
objMail.To = emaila.Text;
objMail.cc = "";
//Enter an address here To include a carbon copy; bcc is For blind carbon
copy's
//Set up Subject Line
objMail.subject = "Quality Assurance Letter";
//To add an attachment, use:
//objMail.attachm ents.add("C:\My AttachmentFile. txt")
string msg;
msg = "body test msg";
objMail.body = msg;
//Use this To display before sending, otherwise call objMail.Send to send
without reviewing
objMail.display ();
//Use this To display before sending, otherwise call objMail.Send to send
without reviewing
//Clean up
objMail = null;
"Scott M." <s-***@nospam.nosp amwrote in message
news:Op******** *****@TK2MSFTNG P04.phx.gbl...
>You can't.

Only client-side code can ask the client to do something. Now, you can
certainly have client code that "asks" the browser to open its default
mail client, and that *might* be Outlook, but again, it might not be.

And, for security reasons, JavaScript (the client code we're talking
about) has no abilities when it comes to the OS.

"andyoye" <an*****@nospam .comwrote in message
news:u7******* *******@TK2MSFT NGP03.phx.gbl.. .
>>How can I launch Outlook on users machines when they click a button on a
web form (InfoPath)?

Thanks



Jul 3 '08 #7
Yes it is a web form, but can the code launch Outlook on a user machine?
"Scott M." <s-***@nospam.nosp amwrote in message
news:%2******** **********@TK2M SFTNGP05.phx.gb l...
You're missing the point. The code you show below will only work if it is
*running* on a machine with Outlook installed. Since you said "web form",
then this could will be running on a web server and there are two issues
with that:

1. Most web servers don't have Outlook installed on them, nor would you
want to as it poses a security risk.
2. Even if the server had Outlook (or the Outlook Primary InterOp
Assembly - PIA), this code runs on the server and won't do anything for
the client.

-Scott

"andyoye" <an*****@nospam .comwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>>I found following from
http://forums.devx.com/showthread.ph...hlight=outlook

looks like I am missing some namespace/referneces as
"Outlook.Appli cation" could not be found.
Outlook.Applic ation objOutlk = new Outlook.Applica tion();
//Outlook
const int olMailItem = 0;
object objMail = new object();
objMail = objOutlk.Create Item(olMailItem );
//Email item
objMail.To = emaila.Text;
objMail.cc = "";
//Enter an address here To include a carbon copy; bcc is For blind carbon
copy's
//Set up Subject Line
objMail.subjec t = "Quality Assurance Letter";
//To add an attachment, use:
//objMail.attachm ents.add("C:\My AttachmentFile. txt")
string msg;
msg = "body test msg";
objMail.body = msg;
//Use this To display before sending, otherwise call objMail.Send to send
without reviewing
objMail.displa y();
//Use this To display before sending, otherwise call objMail.Send to send
without reviewing
//Clean up
objMail = null;
"Scott M." <s-***@nospam.nosp amwrote in message
news:Op******* ******@TK2MSFTN GP04.phx.gbl...
>>You can't.

Only client-side code can ask the client to do something. Now, you can
certainly have client code that "asks" the browser to open its default
mail client, and that *might* be Outlook, but again, it might not be.

And, for security reasons, JavaScript (the client code we're talking
about) has no abilities when it comes to the OS.

"andyoye" <an*****@nospam .comwrote in message
news:u7****** ********@TK2MSF TNGP03.phx.gbl. ..
How can I launch Outlook on users machines when they click a button on
a web form (InfoPath)?

Thanks



Jul 3 '08 #8
Michael,

There are a couple of things wrong with this:

1. The OP asked about opening Outlook on the client but from Web Form code,
which can't be done.
2. Your clean up code is not correct.
a. When calling a COM object via COM InterOp, you must call the
Marshall class's ReleaseComObjec t method, which tells the CLR to release it
connection to the underlying COM object. Since COM objects are freed from
memory when their reference count goes to zero, this step is critical
otherwise the object will persist in memory even though the .NET program
that called it no longer has any reference to it.
b. You really should not ever need to call GC anything except for under
very special circumstances. The GC runs in a separate thread from your .NET
application and the moment you call GC from your application, you force it
to operate in the same thread as your main application. This can actually
result in your application's performance degrading. The bottom line is that
the GC works quite well all on its own and you really shouldn't interfere
with its normal operations because you will most likely not improve matters.

The correct way to "clean up" a COM object from .NET is this:

objOutlook.Quit ();
System.Marshall .ReleaseComObjc t(objOutlook);
objOutlook = null;

-Scott

"Michel Walsh" <va************ *************@n ospam.comwrote in message
news:6D******** *************** ***********@mic rosoft.com...
Add, from Office (Setup/Add/Repair) ".Net Programmability Support" (not as
load on request, but unconditionally ).

Add the reference to Office Interop to your project and the line

using Outlook=Microso ft.Office.Inter op.Outlook;

(note that this alias may help to remove ambiguity about Application and
Outlook.Applica tion)

and, to clean up, the code is missing a lot. Try adding:

objOutlk.Quit() ;
objOutlk= null;
GC.Collect();
GC.WaitForPendi ngFinalizers();
GC.Collect();
GC.WaitForPendi ngFinalizers();
More details in"Microsoft .Net Development For Microsoft Office", Andrew
Whitechapel, Microsoft Press.
Vanderghast, Access MVP

"andyoye" <an*****@nospam .comwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>>I found following from
http://forums.devx.com/showthread.ph...hlight=outlook

looks like I am missing some namespace/referneces as
"Outlook.Appli cation" could not be found.
Outlook.Applic ation objOutlk = new Outlook.Applica tion();
//Outlook
const int olMailItem = 0;
object objMail = new object();
objMail = objOutlk.Create Item(olMailItem );
//Email item
objMail.To = emaila.Text;
objMail.cc = "";
//Enter an address here To include a carbon copy; bcc is For blind carbon
copy's
//Set up Subject Line
objMail.subjec t = "Quality Assurance Letter";
//To add an attachment, use:
//objMail.attachm ents.add("C:\My AttachmentFile. txt")
string msg;
msg = "body test msg";
objMail.body = msg;
//Use this To display before sending, otherwise call objMail.Send to send
without reviewing
objMail.displa y();
//Use this To display before sending, otherwise call objMail.Send to send
without reviewing
//Clean up
objMail = null;
"Scott M." <s-***@nospam.nosp amwrote in message
news:Op******* ******@TK2MSFTN GP04.phx.gbl...
>>You can't.

Only client-side code can ask the client to do something. Now, you can
certainly have client code that "asks" the browser to open its default
mail client, and that *might* be Outlook, but again, it might not be.

And, for security reasons, JavaScript (the client code we're talking
about) has no abilities when it comes to the OS.

"andyoye" <an*****@nospam .comwrote in message
news:u7****** ********@TK2MSF TNGP03.phx.gbl. ..
How can I launch Outlook on users machines when they click a button on
a web form (InfoPath)?

Thanks


Jul 3 '08 #9
Ok for point one, but about point 2, Andrew Whitechapel mentions that
ReleaseComObjec t is scoped to the AppDomain and using it, you risk causing
damage to other applications in the same AppDomain since the RCW is no
longer usable by any of the managed clients in the AppDomain. Furthermore,
you should loop until it returns 0, since sometimes, it may not return 0.
That is why he proposes the sequence I reproduced and conclude that "the
best practice guideline is to not use ReleaseComObjec t" (page 45, "Best
Practices")
Vanderghast, Access MVP
"Scott M." <s-***@nospam.nosp amwrote in message
news:u9******** ******@TK2MSFTN GP02.phx.gbl...
Michael,

There are a couple of things wrong with this:

1. The OP asked about opening Outlook on the client but from Web Form
code, which can't be done.
2. Your clean up code is not correct.
a. When calling a COM object via COM InterOp, you must call the
Marshall class's ReleaseComObjec t method, which tells the CLR to release
it connection to the underlying COM object. Since COM objects are freed
from memory when their reference count goes to zero, this step is critical
otherwise the object will persist in memory even though the .NET program
that called it no longer has any reference to it.
b. You really should not ever need to call GC anything except for
under very special circumstances. The GC runs in a separate thread from
your .NET application and the moment you call GC from your application,
you force it to operate in the same thread as your main application. This
can actually result in your application's performance degrading. The
bottom line is that the GC works quite well all on its own and you really
shouldn't interfere with its normal operations because you will most
likely not improve matters.

The correct way to "clean up" a COM object from .NET is this:

objOutlook.Quit ();
System.Marshall .ReleaseComObjc t(objOutlook);
objOutlook = null;

-Scott

Jul 3 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
8150
by: Daniel Pope | last post by:
Hello Everybody, I'm preparing for doing a daunting task: to access Out look Microsoft Outlook Express(regardles the operating system and Outlook version) from a Java applet (after the client (user) acknowleges to run this applet on his machine). The user has to read the existent user Microsoft Outlook users accounts and to setup another Microsoft Outlook user accont. As I know so far, that the only way is to access from the applet a...
4
17481
by: lauren quantrell | last post by:
Is there a way to open the MS Outlook address book using VBA and then be able to do something with the return value? I want users to click an icon to open the Outlook address book then when an address is selected, populate an Access field with the address. Is this remotely possible? Thanks, lq
5
3925
by: Siv | last post by:
Hi, A little while ago I asked if anyone could help me with how to create an email using MS Outlook that contained an embedded picture file. Thanks to Jay Harlow I was able to get this working using a code example from http://www.outlookcode.com/d/code/htmlimg.htm that details the procedure and with a bit of tweaking I managed to get it working really well. I now find that there is a new user on a laptop that always gets an error at...
2
1817
by: Snig | last post by:
Hi I'm into creating a web application in C# (.NET Framework 1.1) which would list and manage the outlook tasks. If I try to do this in a Windows Application, it works fine. But there are many issues in case of Web application. Code: Outlook.Application app = new Outlook.Application();
6
3633
by: Brad | last post by:
I have a win2003 server workstation with multiple webs, each web has it's own ip address. In VS2005, if I select to open an existing web site, select Local IIS, the dialog correctly displays a list of all of my webs, however if I attempt to open a site under and web other than localhost I receive the message: "Unable to open the Web 'http://localhost/anywebappname'. The Web 'http://localhost/anywebappname' does not exist" Obviously...
3
5814
by: bobdydd | last post by:
Hi Everybody Access 2000, Outlook 2000 Windows XP I am running the code below to open Microsoft Outlook from a Command Button. It works fine until I tried it on a machine that has Office installed on something other than the "C" drive. So can anyone advise me how to open Outlook by using a relative path rather than the code I am using here.
14
5188
by: C | last post by:
Hi, From my ASP.NET application when the user clicksa button I want to be able to programmatically open Outlook, create a new mail, add attachments and set the body text. Is this possible? C.
1
2829
by: keri | last post by:
Hi, I use the below for the user to view their outlook calendar Sub DisplayInbox() Dim myolApp As Outlook.Application Dim myNameSpace As Outlook.NameSpace Dim myFolder As Outlook.MAPIFolder Set myolApp = CreateObject("Outlook.Application") Set myNameSpace = myolApp.GetNamespace("MAPI")
5
2210
by: John | last post by:
Hi I have an Outlook add-in solution which includes a setup project. If I install the Outlook add-in by right clicking on the setup project and sleeting Install then the add-in gets installed fine in Outlook. However if I use the setup generated in the setup project Release folder then even though setup runs and finishes, the Outlook Add-in does not appear in Outlook. What is the problem and how can I fix it? Thanks
0
8987
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9534
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9316
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4597
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.