473,321 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

I want to open OUTLOOK using asp.net C#

I am developing a feedback form in which i want to consume the data in the form like NAME,EMAIL and COMMENTS and then on the click of a button I want OUTLOOK to be opened and the values filled in the form should be filled at their respective fields.
Apr 28 '10 #1
9 25903
Frinavale
9,735 Expert Mod 8TB
Hmm..there is a lot of problems with this idea but I think the biggest problem is: what if the end user does not have Outlook installed? What if the end user's operating system is Linux?

-Frinny
Apr 28 '10 #2
tlhintoq
3,525 Expert 2GB
Let's assume this is for a business where Outlook is the standard, installed on all PC's by the I.T. department.

MSDN C# Developers Center with tutorials
Welcome to Visual Studio

Have you seen the MSDN Code Samples for this? The spent a lot of time creating samples and demos. It seems a shame to not use them.
  • Anonymous Delegates: Demonstrates the use of unnamed delegates to reduce application complexity.
  • Arrays: Shows how to use arrays.
  • Attributes: Shows how to create custom attribute classes, use them in code, and query them through reflection.
  • Collection Classes: Shows how to make non-generic collection classes that can be used with the foreach statement.
  • COM Interop Part I: Shows how to use C# to interoperate with COM objects.
  • COM Interop Part II: Shows how to a use a C# server together with a C++ COM client.
  • Commandline: Demonstrates simple command-line processing and array indexing.
  • Condiational Methods: Demonstrates conditional methods, which provide a powerful mechanism by which calls to methods can be included or omitted depending on whether a symbol is defined.
  • Delegates: Shows how delegates are declared, mapped to static and instance methods, and combined into multicast delegates.
  • Events: Shows how to declare, invoke, and configure events in C#.
  • Explicit Interface: Demonstrates how to explicitly implement interface members and how to access those members from interface instances.
  • Generics: Shows how to make generic collection classes that can be used with the foreach statement.
  • Hello World: A Hello World application.
  • Indexers Part I: Shows how C# classes can declare indexers to provide array-like access to objects.
  • Indexers Part II: Shows how to implement a class that uses indexed properties. Indexed properties enable you to use a class that represents an array-like collection.
  • Libraries: Shows how to use compiler options to create a DLL from multiple source files; also, how to use the library in other programs
  • Named and Optional (C# 4.0): Demonstrates Named and Optional parameters, an alternative to method overloads
  • Nullable: Demonstrates value types, such as double and bool, that can be set to null
  • Office Sample (C# 4.0): Demonstrates how Dynamic and COM Interop make it easy to call Microsoft Office in C# 4.0
  • OLEDB: Demonstrates how to use a Microsoft Access database from C# by creating a dataset and adding tables to it.
  • Operator Overloading: Shows how user-defined classes can overload operators
  • Partial Types: Demonstrates how classes and structures can be defined in multiple C# source-code files
  • PInvoke: Shows how to call exported DLL functions from C#
  • Properties: Shows how properties are declared and used; also demonstrates abstract properties
  • Python Sample (C# 4.0): Learn how to call a Python script by using the Dynamic feature in C# 4.0
  • Security: Discusses .NET Framework security and shows how to modify security permissions in C# by using permission classes and permission attributes
  • Simple Variance (C# 4.0): See how Covariance and Contravariance are supported in generic interfaces and delegates
  • Structs: Shows how to use structs in C#.
  • Threading: Demonstrates various thread activities such as creating and executing a thread, synchronizing threads, interacting between threads, and using a thread pool
  • Unsafe: Shows how to use unmanaged code (code that uses pointers) in C#
  • User Conversions: Shows how to define conversions to and from user-defined types
  • Versioning: Demonstrates versioning in C# by using the override and new keywords
  • XML Documents: Shows how to document code by using XML
  • Yield: Demonstrates how to use the yield keyword to filter items in a collection
Apr 28 '10 #3
Frinavale
9,735 Expert Mod 8TB
Wow that's a lot of information tlhintoq!

If we do assume this is for a business where Outlook is standard on all PCs and that it is the default email program being used.

In this case you could just use a mailto link. However I think you may have problems entering the "default" values using this method.

So you may want to look into opening Outlook manually and creating a "template" message. In this case you will have to develop an ActiveX control. If we assume this is for a business where Outlook is standard on all PCs then we can also assume that Internet Explorer is standard and that no other browser is going to be used to access the website....because Internet Explorer is the only browser that uses ActiveX controls....then we can consider this approach.

It's a bit tricky to develop an ActiveX control using .NET and I would recommend that you use an unmanaged language instead (from past experience). You should be Very Very cautious about developing this control because ActiveX are easily exploited and can be used by malicious code to compromise systems. Do research on ActiveX controls before you even consider this approach.

Assuming that the end user is always going to be using Internet Explorer and that the end user is always going to have Outlook installed and that the end user is going to allow the ActiveX control to run is poor design in my opinion. (Especially since this is a feedback form...which indicates to me that this is not a business application and should be accessible by the public)

I recommend developing a Feedback form that sends the email for the user instead of relying on all of these assumptions. You would allow the user to enter their Name, Email Address, and Comments into TextBoxes (or TextAreas) on the page and you would have a "send feedback" button. When the user clicks the send feedback button you would validate to make sure that a name was provided, a valid email was provided, and that the comments are valid to your standards (eg: no html code or JavaScript...no links that could be harmful). After validating you would create the body of the email that you want to send in the format that you would like the email to be in...and then send the email. Here is a quick reference on how to send an email in .NET.

Using this approach does not depend on the user having Outlook installed...it does not depend on the user using Internet explorer...it does not depend on the user choosing to allow a (potentially harmful) ActiveX control to execute....it doesn't even care if the user is using the Windows Operating system. It allows everyone to send feedback to you and it gives you some control over the format and content of the email sent. (You don't have control over what the user enters into Outlook and so the email sent using Outlook could be missing their name or their email address...or it could contain unwanted links/html/javascript that could be harmful to the person opening the feedback email)

-Frinny
Apr 28 '10 #4
tlhintoq
3,525 Expert 2GB
Finny: Wow that's a lot of information tlhintoq!
It's a copy/paste from my standard responses. Direct from the MSDN site.

By doing a google for "C# create outlook email" I found this MSDN sample for creating a message in C# using the Office.Outlook namespace.

I know nothing of ASP.net, but if you have all your addresses and information as variables, then the server can do this side of it. Right?

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Reflection;     // to use Missing.Value
  3. // TO DO: If you use the Microsoft Outlook 11.0 Object Library, uncomment the following line.
  4. // using Outlook = Microsoft.Office.Interop.Outlook;
  5.  
  6. namespace SendHTMLMail
  7. {
  8.    public class Class1
  9.    {
  10.       public static int Main(string[] args)
  11.       {
  12.          try
  13.          {
  14.             // Create the Outlook application.
  15.             Outlook.Application  oApp = new Outlook.Application();
  16.  
  17.             // Get the NameSpace and Logon information.
  18.             Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
  19.  
  20.             // Log on by using a dialog box to choose the profile.
  21.             oNS.Logon(Missing.Value, Missing.Value, true, true); 
  22.  
  23.             // Alternate logon method that uses a specific profile.
  24.             // TODO: If you use this logon method, 
  25.             //  change the profile name to an appropriate value.
  26.             //oNS.Logon("YourValidProfile", Missing.Value, false, true); 
  27.  
  28.             // Create a new mail item.
  29.             Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
  30.  
  31.             // Set the subject.
  32.             oMsg.Subject = "Send Using OOM in C#";
  33.  
  34.             // Set HTMLBody.
  35.             String sHtml;
  36.             sHtml = "<HTML>\n" + 
  37.                "<HEAD>\n" +
  38.                "<TITLE>Sample GIF</TITLE>\n" +
  39.                "</HEAD>\n" +
  40.                "<BODY><P>\n" + 
  41.                "<h1><Font Color=Green>Inline graphics</Font></h1></P>\n" +
  42.                "</BODY>\n" + 
  43.                "</HTML>";
  44.             oMsg.HTMLBody = sHtml;
  45.  
  46.             // Add a recipient.
  47.             Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
  48.             // TODO: Change the recipient in the next line if necessary.
  49.             Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("email address");
  50.             oRecip.Resolve();
  51.  
  52.             // Send.
  53.             oMsg.Send();
  54.  
  55.             // Log off.
  56.             oNS.Logoff();
  57.  
  58.             // Clean up.
  59.             oRecip = null;
  60.             oRecips = null;
  61.             oMsg = null;
  62.             oNS = null;
  63.             oApp = null;
  64.          }
  65.  
  66.          // Simple error handling.
  67.          catch (Exception e)
  68.          {
  69.             Console.WriteLine("{0} Exception caught.", e);
  70.          }  
  71.  
  72.          // Default return value.
  73.          return 0;
  74.  
  75.       }
  76.    }
  77. }
Apr 28 '10 #5
Frinavale
9,735 Expert Mod 8TB
:) I still don't think that depending on Outlook is a good idea....I still don't think that developing an ActiveX control is a good idea....

I still think that the feedback email should be sent by the web application so that the user is always able to send feedback regardless of the OS they're using....

But then again, that's me :)

-Frinny

PS my previous post was interrupted at the time...I added more info.
Apr 28 '10 #6
hey in my org. the defalut app is outlook. so it is assumed that outlook is being used.
2nd is that i have cracked the code
here it is
Expand|Select|Wrap|Line Numbers
  1. using System.Net.Mail;
  2. using System.Web.UI.HtmlControls;
  3. using System.IO;
  4. using System.Diagnostics;
  5. using Outlook = Microsoft.Office.Interop.Outlook;
  6.  
  7.  
  8. public partial class Feedback : System.Web.UI.Page
  9. {
  10.     protected void Page_Load(object sender, EventArgs e)
  11.     {
  12.  
  13.     }
  14.     protected void btnFSubmit_Click(object sender, EventArgs e)
  15.     {
  16.         try
  17.         {
  18.             //create the mail message
  19.             MailMessage mail = new MailMessage();
  20.  
  21.             //set the addresses
  22.             mail.From = new MailAddress(txtYourEmail.Text);
  23.             mail.To.Add("402234@infosys.com");
  24.  
  25.             //set the content
  26.             mail.Subject = "Feedback";
  27.             mail.Body = txtComments.Text;
  28.  
  29.             //send the message
  30.             SmtpClient smtp = new SmtpClient("localhost");
  31.             smtp.Send(mail);
  32.         }
  33.         catch (System.Exception)
  34.         {
  35.             bool Running = false;
  36.             Process[] List = Process.GetProcesses();
  37.  
  38.             foreach (Process proc in List)
  39.             {
  40.                 if (proc.ProcessName.ToLower().Equals("outlook"))
  41.                 {
  42.                     Running = true;
  43.                 }
  44.             }
  45.  
  46.             if (!Running)
  47.             {
  48.                 Process.Start("Outlook.exe");
  49.             }
  50.  
  51.             Microsoft.Office.Interop.Outlook.Application objApp = new Microsoft.Office.Interop.Outlook.Application();
  52.             Microsoft.Office.Interop.Outlook.MailItem objMail;
  53.             objMail = (Microsoft.Office.Interop.Outlook.MailItem)objApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
  54.             objMail.To = "402234@infosys.com";
  55.             objMail.Subject = "Testmail";
  56.             objMail.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML;
  57.             objMail.Body = txtComments.Text ;
  58.             objMail.Send();
  59.         }
  60.     }
  61. }
Apr 30 '10 #7
Frinavale
9,735 Expert Mod 8TB
I'm glad you solved your problem :)
Apr 30 '10 #8
HI,
I performed all the operation from web application but not able to open window in intranet system i.e infront of app users
I am getting below error
Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80070005.

Any idea how to overcome this problem
Sep 2 '10 #9
Frinavale
9,735 Expert Mod 8TB
That error means that a DLL is missing.
This usually means that the end user does not have the software installed.

Install the software that your application is using and the problem will go away.

Well maybe not, you also have to make sure that the user running your application has sufficient permissions to run the software that your application uses as well.

-Frinny
Sep 3 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: PerryC | last post by:
All, How to ensure SendObject open Outlook and Not Outlook Express? Most pc here at work will default to open OL but on one pc, it open up OL Express. How to fix this in the code? P.S.: I...
3
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...
14
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? ...
9
by: ARC | last post by:
In case anyone has ran into this yet. The following code used to work with older versions of the MS Outlook library, but would error out in 2007: Dim objOutlook As Outlook.Application Dim...
3
by: ganesh22 | last post by:
Hi, how to open Microsoft Outlook using C# code? bcoz my requirement is there is a linkbutton in gridview.that linkbutton text is one email id. when i click that link button one Outlook comppose...
23
by: andyoye | last post by:
How can I launch Outlook on users machines when they click a button on a web form (InfoPath)? Thanks
1
by: Dean Kemp | last post by:
Hi I have designed a button that sends a mail “automated” by the system. But it doesn’t work if outlook is closed. And I have a string of code that opens outlook but then it opens on top of my app....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.