Open outlook message window

  • Thread starter Thread starter Andy
  • Start date Start date
A

Andy

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 recipients and leave it there for the
user to finish filling out.

What classes am I looking for?
 
You have to add a reference to the Outlook Interop first, then doing
something like this should work:

Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg =
(Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Recipient oRecip;

Then for every recipient you want to add:

oRecip = (Outlook.Recipient)oMsg.Recipients.Add("(e-mail address removed)");
oRecip.Resolve();

Then use this call to display the message window:

oMsg.Display(true);

Finally, remember to set all objects to null once you are done:

oRecip = null;
oMsg = null;
oApp = null;

Hope this helps.

Sincerely,
Kevin Wienhold
 
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 recipients and leave it there for the
user to finish filling out.

What classes am I looking for?

Well, first of all you need to add an Interop to your project for
Outlook. In the Solution Explorer, right-click on "References" under
your project and choose "Add Reference...". Go to the COM tab. Which
entry you need to add depends upon your version of Office.

For example, I have an interop for Office XP. Once I add a reference to
the COM component for Outlook XP, I can reference the namespace
Outlook. My code looks like this:

Outlook.Application outlookApp = new Outlook.Application();
Outlook.MailItem message =
(Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
message.Subject = "Hello";
message.Recipients.Add("(e-mail address removed)");
message.Body = "Hello. Hope you're doing well.";
int attachmentLocation = 1;
message.Attachments.Add(fileName, Outlook.OlAttachmentType.olByValue,
attachmentLocation, displayName);
message.Display(false);
 
Thanks to you both! I assume the steps are the same with VSTO.

I haven't used VSTO, but the Microsoft presentations I've been to seem
to indicate that it is substantially different, and _much_ easier to
use.

You'll still have to add some sort of a reference to your project, but
the object hierarchy may be different.
 

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

Back
Top