473,395 Members | 2,222 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,395 software developers and data experts.

Open outlook compose window

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;
_ set message attributes

How can I do it?

Thank you.

Max

Nov 22 '05 #1
2 3727
To use Outlook add a COM reference to Outlook library. Here's a sample of
opening a mail item and setting some properties. It exposes an
Attachments.Add property but I have not tested it.

private void OutlookMail(string Subject, string Body)
{
Outlook.ApplicationClass app = new Outlook.ApplicationClass();
Outlook.NameSpaceClass ns = (NameSpaceClass)app.GetNamespace("mapi");
ns.Logon("", "", true, true);
Outlook.MailItem mi =
(Outlook.MailItem)app.CreateItem(Outlook.OlItemTyp e.olMailItem);
mi.Subject = Subject;
mi.HTMLBody = Body;
mi.Display(1); // show it non - modally
app = null;
ns.Logoff();
ns = null;
mi = null;
}

To use the default mail client you can simply execute a mailto: URI.
System.Diagnostics.Process.Start(string.Format("ma ilto:{0}?Subject={1}&Body=
{2}", To, Subject, Body));
You can also access the System.Web.Mail instead of using Outlook or find a
SMAPI wrapper (http://www.codeproject.com/csharp/simplemapidotnet.asp). As
usual, each method has pros and cons, so check them out and see which fits
best for your needs.

Problems I can recall:
SMAPI - didn't see a way to set HTML format. Doesn't show up in Sent Items.
System.Web.MailMessage - doesn't open a window to set To and From address,
would have to set in code or get input from user.
Outlook - Requires that you reference a COM dll. Distribution issues for
rich client.
URL: No attachments, length of URL limited to 255. Cannot invoke Send.

Be sure to do lots of testing as virus protection or windows security may
try to block you.

HTH,
Eric Cadwell
http://www.origincontrols.com
Nov 22 '05 #2
Thank you very much.

Still a few comments/questions:

-----Original Message-----
To use Outlook add a COM reference to Outlook library. Here's a sample ofopening a mail item and setting some properties. It exposes an
Attachments.Add property but I have not tested it.

private void OutlookMail(string Subject, string Body)
{
Outlook.ApplicationClass app = new Outlook.ApplicationClass();
Outlook.NameSpaceClass ns = (NameSpaceClass)app.GetNamespace("mapi");ns.Logon("", "", true, true);
Outlook.MailItem mi =
(Outlook.MailItem)app.CreateItem(Outlook.OlItemTy pe.olMailItem);
mi.Subject = Subject;
mi.HTMLBody = Body;
mi.Display(1); // show it non - modally
app = null;
ns.Logoff();
ns = null;
mi = null;
}
Can I use similar code to access Outlook Express?

To use the default mail client you can simply execute a mailto: URI.System.Diagnostics.Process.Start(string.Format("m ailto:{0}?Subject={1}&Body=
{2}", To, Subject, Body));

The above code launches in any case the compose window of
Outlook Express, even if I work on a system having Netscape
Mail as the default mail client.

Besides that (it's not really a big problem since my
application will probably have to interact with Outlook
Express and not with Netscape...), I need to directly add
an attachment to the email message, with no user action...

Thanks Again.

Max

Nov 22 '05 #3

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

Similar topics

15
by: Sven Templin | last post by:
Hello all, our configuration is as following described: - OS: Windows 2000 - Apache server 1.3 - Php 3.8 - MS outlook client 2000 _and_ no SMTP server available in the whole intranet.
13
by: ~ Le Naja ~ | last post by:
Hello evrybody, First, I hope you will understand my English because I come from Belgium ! :-) Here is what I want to know if you have the kindess to help me ! :-) I use the code above to mail...
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; _...
13
by: Dave Holmes | last post by:
Is there a way to keep an other application from opening a link in a browser where I am running an ASP application? For example, I have an ASP application open in a browser. If I click on a link...
4
by: Timothy Madden | last post by:
Hello all I have a little problem and I hope it is simple. I have a form on my page and I have to open a pop-up window with the page serverd after the form submit. I know I can compose the URL...
2
by: jim | last post by:
I'm looking for a way to open up a compose new e-mail message dialog (such as from Outlook, Eudora, etc) using C# code behind. C# code that will do the same thing as: ...
14
by: John | last post by:
Hi Is there a way to e-mail using outlook2002 from within vb.net without getting the nasty "An application is trying to access you outlook..." message? Thanks Regards
3
by: RK | last post by:
I am trying to create a .net application which will get the emailid's from list of contacts and will call the "New Mail Message" window of the outlook to compose a new email. All the email -id's...
4
by: douglaswade | last post by:
I am new to Access, but I find this answer a little difficult to understand. I have an access query that list late work, I want to run the query and let say the results is ten records. I want one...
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
0
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,...
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.