473,396 Members | 1,814 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,396 software developers and data experts.

open outlook

hello,
i'm working on c# 2005, and i want to open m.outlook(2003) without sending the email, but open an email message.

how can i do that?


thanks,
lala
May 21 '07 #1
5 2228
Plater
7,872 Expert 4TB
I had to do a lot of digging for this one when I needed it, so here's a little class:
Expand|Select|Wrap|Line Numbers
  1. static class OutlookEmail
  2.     {
  3.         private static Microsoft.Office.Interop.Outlook.Application oApp= new Microsoft.Office.Interop.Outlook.Application();
  4.         private static Microsoft.Office.Interop.Outlook._NameSpace oNameSpace;
  5.         private static Microsoft.Office.Interop.Outlook.MAPIFolder oOutboxFolder;
  6.  
  7.         public static void CreateEmail(string[] toValues, string subjectValue, string bodyValue)
  8.         {
  9.             //oApp = new Microsoft.Office.Interop.Outlook.Application();
  10.             oNameSpace = oApp.GetNamespace("MAPI");
  11.             oNameSpace.Logon(null, null, true, true);
  12.             oOutboxFolder = oNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderOutbox);
  13.  
  14.             Microsoft.Office.Interop.Outlook._MailItem oMailItem = (Microsoft.Office.Interop.Outlook._MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
  15.  
  16.             string theTO = "";
  17.             foreach(string toVal in toValues)
  18.             {
  19.                 //oMailItem.Recipients.Add(toVal);
  20.                 theTO += toVal + "; ";
  21.             }
  22.             oMailItem.To = theTO;
  23.             oMailItem.Subject = subjectValue;
  24.             oMailItem.Body = bodyValue;
  25.             //oMailItem.SaveSentMessageFolder = oOutboxFolder;
  26.             oMailItem.Display(null);
  27.         }
  28. }
  29.  
Be sure to also include a reference to:
Microsoft Outlook 11.0 Object Library
May 21 '07 #2
it works :)
thanks you!!!!!
May 27 '07 #3
mwalts
38
I had to do a lot of digging for this one when I needed it, so here's a little class:
Expand|Select|Wrap|Line Numbers
  1. static class OutlookEmail
  2.     {
  3.         private static Microsoft.Office.Interop.Outlook.Application oApp= new Microsoft.Office.Interop.Outlook.Application();
  4.         private static Microsoft.Office.Interop.Outlook._NameSpace oNameSpace;
  5.         private static Microsoft.Office.Interop.Outlook.MAPIFolder oOutboxFolder;
  6.  
  7.         public static void CreateEmail(string[] toValues, string subjectValue, string bodyValue)
  8.         {
  9.             //oApp = new Microsoft.Office.Interop.Outlook.Application();
  10.             oNameSpace = oApp.GetNamespace("MAPI");
  11.             oNameSpace.Logon(null, null, true, true);
  12.             oOutboxFolder = oNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderOutbox);
  13.  
  14.             Microsoft.Office.Interop.Outlook._MailItem oMailItem = (Microsoft.Office.Interop.Outlook._MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
  15.  
  16.             string theTO = "";
  17.             foreach(string toVal in toValues)
  18.             {
  19.                 //oMailItem.Recipients.Add(toVal);
  20.                 theTO += toVal + "; ";
  21.             }
  22.             oMailItem.To = theTO;
  23.             oMailItem.Subject = subjectValue;
  24.             oMailItem.Body = bodyValue;
  25.             //oMailItem.SaveSentMessageFolder = oOutboxFolder;
  26.             oMailItem.Display(null);
  27.         }
  28. }
  29.  
Be sure to also include a reference to:
Microsoft Outlook 11.0 Object Library
That's neat, but if you don't mind me asking, why not just use mailto:whatever@someplace.ca,someotherguy@otherpla ce.com?subbject=blah&body=BlahAsWell

If you run the above (well double check the mailto syntax, but you get the idea) as a process with UseShellExecute = true, it will open whatever your default mail program is in the same manner, regardless of if they have outlook installed.

Your example does force it to be outlook though, which could be useful, and I'm sure gives you much greater control overall.

Have fun,

-mwalts
May 28 '07 #4
prabunewindia
199 100+
you can also refer the below article for more understanding

outlook
Prabu

That's neat, but if you don't mind me asking, why not just use mailto:whatever@someplace.ca,someotherguy@otherpla ce.com?subbject=blah&body=BlahAsWell

If you run the above (well double check the mailto syntax, but you get the idea) as a process with UseShellExecute = true, it will open whatever your default mail program is in the same manner, regardless of if they have outlook installed.

Your example does force it to be outlook though, which could be useful, and I'm sure gives you much greater control overall.

Have fun,

-mwalts
May 29 '07 #5
Plater
7,872 Expert 4TB
That's neat, but if you don't mind me asking, why not just use mailto:whatever@someplace.ca,someotherguy@otherpla ce.com?subbject=blah&body=BlahAsWell

If you run the above (well double check the mailto syntax, but you get the idea) as a process with UseShellExecute = true, it will open whatever your default mail program is in the same manner, regardless of if they have outlook installed.

Your example does force it to be outlook though, which could be useful, and I'm sure gives you much greater control overall.

Have fun,

-mwalts

Well the request was for the ability to open outlook, not the default mailer.

As for Prabu, I believe I used some article I found here back when I created mine, but had to hack it apart to get it to work better. (I don't like having the "an application is trying to use outlook" popup coming up every 5secs as the article I read produced) I haven't gone through yours, but emailing help is always usefull. (I'm creating my own custom smtp class STILL)
May 29 '07 #6

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

Similar topics

2
by: MaxH | last post by:
I need to perform programmatically from a C# .net application the following tasks: _ open an outlook (or default e-mail client) compose message window; _ attach a document to the new message; _...
3
by: Jordan | last post by:
I created and access application that sends e-mails automaticaly to our clients, over 1.500 e-mails daily. I am using the MS Outlook components to create the e-mail with HTML code. All works...
4
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...
0
by: Moti | last post by:
I want to open, NOT to send, new email message. I use: Outlook.Application oApp = new Outlook.Application(); Outlook._NameSpac oNameSpace= oApp.GetNamespace("MAPI");...
6
by: Barkster | last post by:
I'm trying to send using outlook but I get an error on the directcast line if I don't have outlook open. Works fine if it is open. What do I need to do to be able to send without having outlook...
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? ...
4
by: Andy | last post by:
Hi, I have a C# application and I'd like it to use Outlook 2003 to send messages. I don't want to send them programmaticlly though; I just want to open the New Messge window, set the...
1
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...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.