Link to home
Start Free TrialLog in
Avatar of adamtrask
adamtrask

asked on

starting an outlook email from inside a win form in C#

Good morning,,
I created an application in C# where, at some point, the user will need to use outlook  to send an email to a colleague.

The email address of the percipient as well as the body and subject matter are placed in text boxes in the win form waiting to be moved or copied to the outgoing email in Outlook.

So, basically my question is: how do I run outlook form inside a win form, select a new email copy the recipient email address and the body of text into the email and send it.

Thank you
SOLUTION
Avatar of FarWest
FarWest

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of adamtrask
adamtrask

ASKER

FarWest: Would you give me an example, please?

Thank you
What namespace of reference do I need to use...?
OK . I will send it once I get back to my computer
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is one of the problems: I actually found several examples of code which list the namespace you give but II try using it I get a red line under the "Office" part... I am attaching a screen shot. Thanks.User generated image
I should add that i am using Visual Studio 2010
OK, I now know how to add a reference to the project.... and will be able to try your code. Thank you for your patience FarWest...
Nevermind . you are welcome  and sorry for not  mentioning the reference  part
SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you both...

I couldn't respond during the weekend because I don't have access to Outlook at home. Now that I am back in the office I was able to test what I got from you and a lot of other code I found online.
Finally I was able to do what I needed with the following piece of code which I would like to share with others who might find a need for it:

 private void CreateMailItem()
        {
            Outlook.Application outlookApp = new Outlook.Application();
            Outlook.MailItem mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
            mailItem.Subject = this.txtSubject.Text;
            mailItem.To = txtAddress.Text;
            mailItem.Body = txtBody.Text;
            mailItem.Importance = Outlook.OlImportance.olImportanceLow;
            mailItem.Display(false);
        }
Éric Moreau: Right now I don't plan to include attachments to my code, but I am sure your article will be of help at some point in the future. Thank you

Adam
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you guys.